我使用以下函数通过存储过程在数据库中插入值。但我有例外sqlConnection.Open()
;如何解决这个问题?
try
{
string dbConnectionString = "something";
SqlConnection sqlConnection = new SqlConnection(dbConnectionString);
SqlCommand command = new SqlCommand("sp_Test", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@id ", SqlDbType.Int).Value = TextBox1.Text;
command.Parameters.AddWithValue("@FullName", SqlDbType.VarChar).Value = TextBox2.Text;
sqlConnection.Open();
command.ExecuteNonQuery();
sqlConnection.Close();
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
}