+ -
当前位置:首页 → 问答吧 → 超级紧急

超级紧急

时间:2011-12-05

来源:互联网

我的注册代码
  using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Page;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page 
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlConnection sqlconn = new SqlConnection(sqlconnstr);
  SqlCommand sqlcommand = new SqlCommand();
  sqlcommand.Connection = sqlconn;
  sqlcommand.CommandText = "insert into customer(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 (Exception ex)
  {
  Label1.Text = "" + ex.Message;
  }
  finally
  {
  sqlcommand = null;
  sqlconn.Close();
  sqlconn = null;
  }
  }

}
但是有错误,错误提示是
错误 1 “string”不包含“Text”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?) C:\Users\pig\Documents\Visual Studio 2010\WebSites\WebSite1\Default.aspx.cs 28 62 C:\...\WebSite1\

作者: LYE1219   发布时间: 2011-12-05

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Page;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page 
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlConnection sqlconn = new SqlConnection(sqlconnstr);
  SqlCommand sqlcommand = new SqlCommand();
  sqlcommand.Connection = sqlconn;
  sqlcommand.CommandText = "insert into customer(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 (Exception ex)
  {
  Label1.Text = "" + ex.Message;
  }
  finally
  {
  sqlcommand = null;
  sqlconn.Close();
  sqlconn = null;
  }
  }

}

看红色标记部分,怎么控件的ID名称起了了叫ID的,换个名字customerID

作者: taomanman   发布时间: 2011-12-05

还有参数注意大小写一致,看下面红色标记部分。
sqlcommand.CommandText = "insert into customer(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);

作者: taomanman   发布时间: 2011-12-05

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那些什么?在哪里定义的?

作者: dongxinxi   发布时间: 2011-12-05