问题描述
我的注册代码usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.Page;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){stringsqlconnstr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;SqlConnectionsqlconn=newSqlConnection(sqlconnstr);SqlCommandsqlcommand=newSqlCommand();sqlcommand.Connection=sqlconn;sqlcommand.CommandText="insertintocustomer(customerID,Name,Password,Address,Phone,Email)values(@customerID,@Name,@Password,@Address,@Phone,@Email)";sqlcommand.Parameters.AddWithValue("@customerID",ID.Text);sqlcommand.Parameters.AddWithValue("@Name",name.Text);sqlcommand.Parameters.AddWithValue("@Password",password.Text);sqlcommand.Parameters.AddWithValue("@Address",address.Text);sqlcommand.Parameters.AddWithValue("@phone",phone.Text);sqlcommand.Parameters.AddWithValue("@Email",email.Text);try{sqlconn.Open();sqlcommand.ExecuteNonQuery();}catch(Exceptionex){Label1.Text=""+ex.Message;}finally{sqlcommand=null;sqlconn.Close();sqlconn=null;}}}但是有错误,错误提示是错误1“string”不包含“Text”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“Text”(是否缺少using指令或程序集引用?)C:UserspigDocumentsVisualStudio2010WebSitesWebSite1Default.aspx.cs2862C:...WebSite1
解决方案
解决方案二:
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.Page;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){stringsqlconnstr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;SqlConnectionsqlconn=newSqlConnection(sqlconnstr);SqlCommandsqlcommand=newSqlCommand();sqlcommand.Connection=sqlconn;sqlcommand.CommandText="insertintocustomer(customerID,Name,Password,Address,Phone,Email)values(@customerID,@Name,@Password,@Address,@Phone,@Email)";sqlcommand.Parameters.AddWithValue("@customerID",ID.Text);sqlcommand.Parameters.AddWithValue("@Name",name.Text);sqlcommand.Parameters.AddWithValue("@Password",password.Text);sqlcommand.Parameters.AddWithValue("@Address",address.Text);sqlcommand.Parameters.AddWithValue("@phone",phone.Text);sqlcommand.Parameters.AddWithValue("@Email",email.Text);try{sqlconn.Open();sqlcommand.ExecuteNonQuery();}catch(Exceptionex){Label1.Text=""+ex.Message;}finally{sqlcommand=null;sqlconn.Close();sqlconn=null;}}}看红色标记部分,怎么控件的ID名称起了了叫ID的,换个名字customerID
解决方案三:
还有参数注意大小写一致,看下面红色标记部分。sqlcommand.CommandText="insertintocustomer(customerID,Name,Password,Address,Phone,Email)values(@customerID,@Name,@Password,@Address,@Phone,@Email)";sqlcommand.Parameters.AddWithValue("@customerID",ID.Text);sqlcommand.Parameters.AddWithValue("@Name",name.Text);sqlcommand.Parameters.AddWithValue("@Password",password.Text);sqlcommand.Parameters.AddWithValue("@Address",address.Text);sqlcommand.Parameters.AddWithValue("@phone",phone.Text);sqlcommand.Parameters.AddWithValue("@Email",email.Text);
解决方案四:
sqlcommand.Parameters.AddWithValue("@customerID",ID.Text);sqlcommand.Parameters.AddWithValue("@Name",name.Text);sqlcommand.Parameters.AddWithValue("@Password",password.Text);sqlcommand.Parameters.AddWithValue("@Address",address.Text);sqlcommand.Parameters.AddWithValue("@phone",phone.Text);sqlcommand.Parameters.AddWithValue("@Email",email.Text);ID、name那些什么?在哪里定义的?
解决方案五:
掌声给2楼,为什么都不用F11了