Hi,
insert or update is going with null value .
In my update button click, if txt_VAT is null i have to give a message and set the focus to txt_VAT text box.
private void btn_update_Click(object sender, EventArgs e)
{
MessageBox.Show("please enter the vat:");
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("update tbl_vat set vat=@vat where vatid=1", con);
cmd.Parameters.AddWithValue("@vat", txt_VAT.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
if (cmd.ExecuteNonQuery() != 1)
{
cmd = new SqlCommand("insert into tbl_vat (VatId,Vat) values('1',@vat)", con);
cmd.Parameters.AddWithValue("@vat", txt_VAT.Text);
cmd.ExecuteNonQuery();
}
con.Close();
txt_VAT.Text = "";
MessageBox.Show("vat updated succesfully");
//DataTable dt = new DataTable();
//da.Fill(dt);
}
Best,
Sudheep.