cmd.ExecuteNonQuery();提示错误。求解答
usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;us...
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button6_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == "" || this.TextBox2.Text == "" || this.TextBox4.Text == "")
{
Response.Write("请输入完整信息后再注册!!");
}
if (TextBox2.Text != TextBox4.Text)
{
Response.Write("请输入正确信息后再注册!!");
}
else
{
string connectionString = "Data Source=2012-20130903LZ;Initial Catalog=book;Integrated Security=true";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string strSQL =" insert into book(user,password) values(" + TextBox1.Text + "," + TextBox2.Text + ")";
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.ExecuteNonQuery();
Response.Write("注册成功");
conn.Close();
}
}
} 展开
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button6_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == "" || this.TextBox2.Text == "" || this.TextBox4.Text == "")
{
Response.Write("请输入完整信息后再注册!!");
}
if (TextBox2.Text != TextBox4.Text)
{
Response.Write("请输入正确信息后再注册!!");
}
else
{
string connectionString = "Data Source=2012-20130903LZ;Initial Catalog=book;Integrated Security=true";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string strSQL =" insert into book(user,password) values(" + TextBox1.Text + "," + TextBox2.Text + ")";
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.ExecuteNonQuery();
Response.Write("注册成功");
conn.Close();
}
}
} 展开
2个回答
展开全部
string strSQL =string.Format( " insert into [book]([user],[password]) values ('{0}' , '{1}'",TextBox1.Text.Trim(), TextBox2.Text.Trim());
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询