代码:
string conStr = "Data Source=DESKTOP-2I8T0VE\SQLEXPRESS;Initial Catalog=SqlDemos;integrated security=true";
//string conStr = ConnectionStringHelper.GetCurrentConnectionString();
using (SqlConnection conn = new SqlConnection(conStr))
{
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
string strSql = $"insert into SqlDemos UserName, UserAge, UserPwd, DelFlag,CreateDate values {txtUserName.Text}, " +
$"{int.Parse(txtAge.Text)},{22},int.Parse{txtPwd1.Text},{1},{DateTime.Now}";
cmd.CommandText = strSql;
cmd.ExecuteNonQuery();
}
}
MessageBox.Show("OK");
注释掉ExecuteNonQuery();提示插入成功,但数据库内并无该数据
附上数据库数据类型:
请问该如何修改避免堆栈出错且成功插入数据呢?