Hi.. I'm trying to insert data from a textbox. But there's an error..here's my code:
protected void Button1_Click(object sender, EventArgs e)
{
String insertSQL;
insertSQL = "INSERT INTO SERVICES (";
insertSQL += "Service_Code, Service_Name)";
insertSQL += "VALUES (";
insertSQL += "@Service_Code, @Service_Name)";
String connectionstring = WebConfigurationManager.ConnectionStrings["HelpDesk_System"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(insertSQL, conn);
cmd.Parameters.AddWithValue("@Service_Code", TextBox1.Text);
cmd.Parameters.AddWithValue("@Service_Name", TextBox2.Text);
int added = 0;
try
{
conn.Open();
added = cmd.ExecuteNonQuery();
UpdatePanel1.Update();
conn.Close();
}
catch (Exception err)
{
Label1.Text = "Error inserting";
Label2.Text += err.Message;
}
}
}
|
the error states that:
Object reference not set to an instance of an object.
What does it mean?
Thank you.
---ms SQL
---C#
---asp.net
Dipa AhujaPosted May 27, 2010, 10:06 AM
Dipa AhujaPosted May 27, 2010, 1:13 PM
CrishPosted May 27, 2010, 12:44 PM
You can not insert value in Identity (primary key value where you have set autoincrement true) in table 'SERVICES'. So don't insert this ID value in this table. so it will work.
Heaven ValenzonaPosted May 27, 2010, 10:28 AM
Dipa AhujaPosted May 27, 2010, 10:09 AM
Object reference not set to an instance of an object.
Heaven ValenzonaPosted May 27, 2010, 9:40 AM
Dipa AhujaPosted May 27, 2010, 8:15 AM