在visual studio中往数据库中的表中添加信息:代码如下
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=.;DataBase=HRM_26wsy;integrated security=SSPI";
string strSql;
strSql = "Insert Into UserInfo(UserName,Passerword,Role)Values('" + txtName.Text + "','" +txtPassword.Text+ "'," + Convert.ToInt16(txtRole.Text) + ")";
SqlCommand cmd = new SqlCommand(strSql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
lblMessage.Text = "已添加成功";
}
protected void Button2_Click(object sender, EventArgs e)
{
txtName.Text = " ";
txtPassword.Text = " ";
txtPassword1.Text = " ";
txtRole.Text = " ";
lblMessage.Text = " ";
}
但在运行时会出现这种错误:编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS1061: “ASP.添加记录_aspx”不包含“TextBox1_TextChanged”的定义,并且找不到可接受类型为“ASP.添加记录_aspx”的第一个参数的扩展方法“TextBox1_TextChanged”(是否缺少 using 指令或程序集引用?
还有我在开头已经打了 using System.Data;
using System.Data.SqlClient;