if (btnSave.Text == "Save")
{
SqlCommandBuilder cmdbSection;
DataRow newrow;
ds = new DataSet();
ad = new SqlDataAdapter("select strTestName from PEHMstTest where strTestName='" + txttestname.Text + "'", SqlCon);
ad.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
DataSet ds1 = new DataSet();
SqlDataAdapter ad1 = new SqlDataAdapter("select * from PEHMstTest", SqlCon);
ad1.Fill(ds1);
newrow = ds1.Tables[0].NewRow();
newrow[0] = new_num();
newrow[1] = txttestname.Text;
newrow[2] = txtcharges.Text;
ds1.Tables[0].Rows.Add(newrow);
cmdbSection = new SqlCommandBuilder(ad1);
ad1.Update(ds1);
lblMsg.ForeColor = Color.Green;
lblMsg.Text = "Records saved successfully";
}
else
{
lblMsg.ForeColor = Color.Red;
lblMsg.Text = "Test Detail Already Exists, Give a different name.";
}
}
[edit]added pre tag[/edit]