📜  如何解决 asp.net 中 ExecuteNonQuery() 中的错误 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:22.350000             🧑  作者: Mango

代码示例1
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Harry\Documents\Visual Studio 2015\WebSites\WebSite2\App_Data\Database.mdf; Integrated Security = True";
con.Open();

// insert command 
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText="INSERT INTO firsttb VALUES ( @n , @p ) ";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@n",TextBox1.Text);
cmd.Parameters.AddWithValue("@p", TextBox2.Text);

cmd.ExecuteNonQuery();

con.Close();