I am working on a school project that includes data-bases. I got the basiscs of SQL programming but I still getting problems. Now I'm stuck on the code that is supposed to add new data into the grid, but it's just not working for some reason.. I tried to find a solution for this problem (as you can see from the code), but nothing worked.. Here is the code.
private void InsertData()
{
string NewCode = GenerateCode();
string NewLetter = txtNewData.Text;
try
{
Connection.Open();
string AddData = "INSERT INTO DictionaryTest (BinNumber,Letter) VALUE (@NewCode,@NewLetter)";
//SqlDataAdapter DataIns = new SqlDataAdapter(AddData, Connection);
SqlCommand DataAdd = new SqlCommand(AddData, Connection);
DataAdd.Parameters.AddWithValue("@NewCode", "00" + NewCode);
DataAdd.Parameters.AddWithValue("@NewLetter", NewLetter);
//DataAdd.ExecuteNonQuery();
//Connection.Open();
//var dt = new DataTable();
//DataIns.Fill(dt);
Connection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
The data that I'm getting from the fucntion GenerateCode() is ok, I tried to insert it into a text box and it was right.