Warning message when adding data to database
This is my code of connection to database:
Public void connection()
{
connection.ConnectionString = "Data Source=localhost;Initial Catalog=base; Integrated Security=true";
connection.Open();
if (connection.State == ConnectionState.Open)
{
Interaction.MsgBox("Connection was successful", MsgBoxStyle.Exclamation, "Status");
}
else
{
Interaction.MsgBox("Connection failed", MsgBoxStyle.Critical, "Status");
}
connection.Close();
}
Whenever I try to save the data in my database but it will give the error message:
Here is my code:
{
try {
connection();
string strRequest = "SELECT * FROM Coaches";
DataTable dtt = default(DataTable);
SqlDataAdapter oSqlDataAdapter = new SqlDataAdapter(strRequest, connection);
DataSet oDataSet = new DataSet("Coaches");
oSqlDataAdapter.Fill(oDataSet, "Coaches");
dtt = oDataSet.Tables("Coaches");
oSqlDataAdapter.InsertCommand = new SqlCommand("INSERT INTO Coaches(Name,Surname,Address,Telephone) Values(@TextBoxName_E,@TextBoxSurname_E,@TextBoxAd _E,@TextBoxTel_E)", connection);
oSqlDataAdapter.InsertCommand.Parameters.Add("@Tex tBoxSurname_E", SqlDbType.NChar, 15, "TextBoxSurname_E");
oSqlDataAdapter.InsertCommand.Parameters.Add("@Tex tBoxTel_E", SqlDbType.Int, 100, "TextBoxTel_E");
DataRow oDataRow = default(DataRow);
byte[] byteArray = { };
oDataRow = oDataSet.Tables("Coaches").NewRow;
oDataRow("TextBoxName_E") = TextBoxName_E.Text;
oDataRow("TextBoxAd_E") = TextBoxAd_E.Text;
oDataRow("TextBoxTel_E") = TextBoxTel_E.Text;
oDataSet.Tables("Coaches").Rows.Add(oDataRow);
oSqlDataAdapter.Update(oDataSet, "Coaches");
oDataSet.Clear();
dtt = oDataSet.Tables("Coaches");
Interaction.MsgBox("Article successfully registered with", MsgBoxStyle.Information, "Status");
connection.Close();
}
catch {
Interaction.MsgBox("Failed registration");
}



Reply With Quote
Copyright Techfuels
Bookmarks