private void UpdateorAddNewRecord(string CustomerID, string CompanyName,string ContactName,string ContactTitle, string Address, string Country, bool isUpdate)
{
SqlConnection Connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
string sqlStatement = string.Empty;
if(!isUpdate)
{
sqlStatement="insert into sachin"+"(CustomerID,CompanyName,ContactName,ContactTitle,Address,Country)"+"VALUES(@CustomerID,@CompanyName,@ContactName,@ContactTitle,@Address,@Country)";
}
else
{
sqlStatement = "UPDATE sachin" +
"SET CompanyName = @CompanyName,ContactName=@ContactName," +
"ContactTitle = @ContactTitle,Address= @Address,Country= @Country" +
" WHERE CustomerID = @CustomerID,";
}
try
{
Connection.Open();
SqlCommand cmd=new SqlCommand(sqlStatement,Connection);
cmd.Parameters.AddWithValue("@CustomerID",CustomerID);
cmd.Parameters.AddWithValue("@CompanyName",CompanyName);
cmd.Parameters.AddWithValue("@ContactName",ContactName);
cmd.Parameters.AddWithValue("@ContactTitle",ContactTitle);
cmd.Parameters.AddWithValue("Address",Address);
cmd.Parameters.AddWithValue("Country",Country);
cmd.CommandType=CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex){
string msg = "insert/update error";
msg+=ex.Message;
throw new Exception(msg);
}
finally {
Connection.Close();
}
}
WHEN I M RUNNING THE AAPPLICATION with gridview and usig store procedureSHOWING ERROR IN UPDATED