写了一个网页,是一个用户注册页面,功能就是将用户在文本框中输入的信息存储到数据库中去,出了点问题.. 10
-----------------------------上面省略一些命名空间usingSystem.Data.SqlClient;publicpartialclassr...
-----------------------------上面省略一些命名空间
using System.Data.SqlClient;
public partial class regist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btregist_Click(object sender, EventArgs e)//点击注册按钮执行下面
{ //建立到数据库的连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=ACER-PC\\SQLEXPRESS;Initial Catalog=workinfo;User ID=sa;Password=123;";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into seinfo(uid,name,password,email,department,phone,address,position,description)values(@uid,@name,@password,@email,@department,@phone,@address,@position,@description);";
cmd.Connection = conn;
SqlParameter parauid = new SqlParameter("@uid",SqlDbType.Char,15);
SqlParameter paraname = new SqlParameter("@name",SqlDbType.Char,10);
SqlParameter parapassword = new SqlParameter("@password",SqlDbType.NChar,15);
SqlParameter paraemail = new SqlParameter("@email",SqlDbType.Char,20);
SqlParameter paradepartment = new SqlParameter("@department",SqlDbType.Char, 10);
SqlParameter paraphone = new SqlParameter("@phone",SqlDbType.Char,20);
SqlParameter paraaddress = new SqlParameter("@address",SqlDbType.Char,10);
SqlParameter paraposition = new SqlParameter("@position",SqlDbType.Char,10);
SqlParameter paradescription = new SqlParameter("@description",SqlDbType.NVarChar,500);
parauid.Value =useridtext.Text ;
paraname.Value =nametext.Text;
paraemail.Value = emailtext.Text;
paradepartment.Value = departmenttext.Text;
paraphone.Value = phonetext.Text;
paraaddress.Value = addresstext.Text;
paraposition.Value = positiontext.Text;
paradescription.Value = descriptiontext.Text;
cmd.Parameters.Add(parauid);
cmd.Parameters.Add(paraname);
cmd.Parameters.Add(parapassword);
cmd.Parameters.Add(paraemail);
cmd.Parameters.Add(paradepartment);
cmd.Parameters.Add(paraphone);
cmd.Parameters.Add(paraaddress);
cmd.Parameters.Add(paraposition);
cmd.Parameters.Add(paradescription);
int record = cmd.ExecuteNonQuery();
Response.Write(record.ToString());
conn.Close();
conn.Dispose();
}
}
我注册页面中用于用户名输入的文本框组件ID名字更改过,就叫useridtext,但是运行就是错误提示上下文中不存在useridtext,后来试过前面加上This 改成了this.useridtext,输入命令的时候也有自动补充完整的提示了,但是再运行又说"regist"不包含useridtext的定义并且找不到一个接受类型为"regist"的第一个参数的扩展方法"useridtext"。请问如何解决? 展开
using System.Data.SqlClient;
public partial class regist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btregist_Click(object sender, EventArgs e)//点击注册按钮执行下面
{ //建立到数据库的连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=ACER-PC\\SQLEXPRESS;Initial Catalog=workinfo;User ID=sa;Password=123;";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into seinfo(uid,name,password,email,department,phone,address,position,description)values(@uid,@name,@password,@email,@department,@phone,@address,@position,@description);";
cmd.Connection = conn;
SqlParameter parauid = new SqlParameter("@uid",SqlDbType.Char,15);
SqlParameter paraname = new SqlParameter("@name",SqlDbType.Char,10);
SqlParameter parapassword = new SqlParameter("@password",SqlDbType.NChar,15);
SqlParameter paraemail = new SqlParameter("@email",SqlDbType.Char,20);
SqlParameter paradepartment = new SqlParameter("@department",SqlDbType.Char, 10);
SqlParameter paraphone = new SqlParameter("@phone",SqlDbType.Char,20);
SqlParameter paraaddress = new SqlParameter("@address",SqlDbType.Char,10);
SqlParameter paraposition = new SqlParameter("@position",SqlDbType.Char,10);
SqlParameter paradescription = new SqlParameter("@description",SqlDbType.NVarChar,500);
parauid.Value =useridtext.Text ;
paraname.Value =nametext.Text;
paraemail.Value = emailtext.Text;
paradepartment.Value = departmenttext.Text;
paraphone.Value = phonetext.Text;
paraaddress.Value = addresstext.Text;
paraposition.Value = positiontext.Text;
paradescription.Value = descriptiontext.Text;
cmd.Parameters.Add(parauid);
cmd.Parameters.Add(paraname);
cmd.Parameters.Add(parapassword);
cmd.Parameters.Add(paraemail);
cmd.Parameters.Add(paradepartment);
cmd.Parameters.Add(paraphone);
cmd.Parameters.Add(paraaddress);
cmd.Parameters.Add(paraposition);
cmd.Parameters.Add(paradescription);
int record = cmd.ExecuteNonQuery();
Response.Write(record.ToString());
conn.Close();
conn.Dispose();
}
}
我注册页面中用于用户名输入的文本框组件ID名字更改过,就叫useridtext,但是运行就是错误提示上下文中不存在useridtext,后来试过前面加上This 改成了this.useridtext,输入命令的时候也有自动补充完整的提示了,但是再运行又说"regist"不包含useridtext的定义并且找不到一个接受类型为"regist"的第一个参数的扩展方法"useridtext"。请问如何解决? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询