inserting data from a textbox..

May 27 2010 7:13 AM
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




Answers (7)