i am trying to update my data from webservice to my database. But once i click invoke in the web service page , and run to this command:"command1.Connection.Open();" i will receive this error message :Object reference not set to an instance of an object.
this is my code:
[WebMethod]
public void UpdateParticulars(string Name, string CLass, string NRIC, float AmountSpent)
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ncpConnectionString2"].ConnectionString))
{
SqlCommand command1 = new SqlCommand("UPDATE Student set Name=@Name, Class=@CLass,StallNo=@StallNo,AmountSpent=@AmountSpent WHERE NRIC = '" + NRIC + "'");
command1.Parameters.AddWithValue("@Name", Name);
command1.Parameters.AddWithValue("@Class", CLass);
command1.Parameters.AddWithValue("@NRIC", NRIC);
command1.Parameters.AddWithValue("@AmountSpent", AmountSpent);
command1.Connection.Open();
command1.ExecuteNonQuery();
}
}