TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
pethu raj
NA
41
3.8k
Object reference not set to an instance of an object.
Oct 1 2017 2:21 PM
Hi,
How can i solve the error "
Object reference not set to an instance of an object.
" .
for the below code.
The error throws in RowUpdating line
cmd.Parameters.AddWithValue("@p1", NAME.Text)
Kindly give a solution for this
protected void getdata()
{
string s = "Select * from Empdetail";
cmd = new SqlCommand(s, conn);
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
singlegrid.DataSource = ds;
singlegrid.DataBind();
}
protected void singlegrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
singlegrid.PageIndex = e.NewPageIndex;
getdata();
}
protected void singlegrid_RowEditing(object sender, GridViewEditEventArgs e)
{
singlegrid.EditIndex = e.NewEditIndex;
getdata();
}
protected void singlegrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string bid = singlegrid.DataKeys[e.RowIndex].Value.ToString();
string s = "delete from Empdetail where EMPID=@p2";
SqlCommand cmd = new SqlCommand(s, conn);
cmd.Parameters.AddWithValue("@p2", bid);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
getdata();
}
protected void singlegrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
singlegrid.EditIndex = -1;
getdata();
}
protected void singlegrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string bid = singlegrid.DataKeys[e.RowIndex].Value.ToString();
TextBox NAME = (TextBox)singlegrid.Rows[e.RowIndex].FindControl("NAME");
TextBox DESIG = (TextBox)singlegrid.Rows[e.RowIndex].FindControl("DESIG");
string s = "update Empdetail set NAME=@p1, DESIG=@p2 where EMPID=@p3";
cmd = new SqlCommand(s, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@p1", NAME.Text);
cmd.Parameters.AddWithValue("@p2", DESIG.Text);
cmd.Parameters.AddWithValue("@p3", bid);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
singlegrid.EditIndex = -1;
getdata();
Reply
Answers (
1
)
Bind GridView From WCF Service Datatable
MVC web api is getting failed while long running task inside