ASP.NET - Qry Err - Asked By Jahir on 10-Feb-12 12:54 AM


I have qry err in this:

cmd=new SqlCommand("update agentoffer set fromdate='"+txfrdate.Text+"',todate='"+txtodate.Text+"', title='"+txtitle.Text+"', description='"+txdescription.Text+"', category='"+txradiocategory.SelectedItem.Text+"'  where id='"+lbid.Text+"'",con); //180 line

it was not update correctly it shows err:

Error:System.NullReferenceException: Object reference not set to an instance of an object. at offers.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in d:\tour\offers.aspx.cs:line 180

here category is radiobuttonlist.
i inserted in agentoffer table  and i have select member radiobtnlist means it want to add that data automatically in member table how ?

send me qry ?

Web Star replied to Jahir on 10-Feb-12 01:37 AM
Query is ok you need to check the parameter value which are passing with the query any one having null referance that's why you are getting error so you need to check your code in debug mode query will be created correctly with textbox and rediobutton value.
dipa ahuja replied to Jahir on 10-Feb-12 06:00 AM
Its advisable to take the parameters when parameter no. are more than 2. This type of queries always confuse you and create problems of single quotes and many other

change your query format to this:

UPDATE Query

 
private void button1_Click(object sender, EventArgs e)
{
     SqlConnection connect = new SqlConnection(ConnString);
     connect.Open();
 
     string q = "Update people set name=@name where id=@id";
 
     SqlCommand comm = new SqlCommand(q, connect);
     comm.Parameters.AddWithValue("name", txtname.Text);
     comm.Parameters.AddWithValue("id", int.Parse(txtid.Text.ToString()));
     comm.ExecuteNonQuery();
     connect.Close();
 
}