protected void Button1_Click(object sender, EventArgs e)
{
string connString = "Data Source=localhost;Initial Catalog=test_db;Integrated Security=True;";
string insertCommand = "INSERT INTO empDetl (empName,addr) values(@empName,@addr)";
string _name = txtName.Text;
string _addr = txtAddr.Text;
using(SqlConnection conn = new SqlConnection(connString))
{
//open DB Connection
conn.Open();
using (SqlCommand cmd = new SqlCommand(insertCommand, conn))
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@empName", _name);
cmd.Parameters.AddWithValue("@addr", _addr);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
此代码无法正常工作。请告诉我错误在哪里。在插入值时它显示“无效的对象名称'empDetl'”但我的表名是empDetl。