try
{
SqlConnection sqlconn = new SqlConnection("Data Source=AAN-PC;Initial Catalog=mon26;Integrated Security=True");
SqlDataAdapter sa = new SqlDataAdapter();
string query;
if(hexvalue =""AA")
query = "insert into Table_1(SensorValue,Time) values(@SV, @TM)";
else
query = "insert into Table_2(SensorValue,Time) values(@SV, @TM)";
sa.InsertCommand = new SqlCommand(query, sqlconn);
sa.InsertCommand.Parameters.AddWithValue("@SV", hexvalue);
sa.InsertCommand.Parameters.AddWithValue("@TM", DateTime.Now.ToString());
sqlconn.Open();
try
{
sa.InsertCommand.ExecuteNonQuery();
}
catch (FormatException ex) { MessageBox.Show(ex.Message); }
MessageBox.Show("Record Inserted");
// Update Datagridview
mon26DataSet1.GetChanges();
table_1TableAdapter.Fill(mon26DataSet1.Table_1);
sqlconn.Close();
}