下面C#语句无法运行!运行时提示说 sqlcommand.ExecuteNonQuery();有错望大神帮助! 15
protectedvoidButton1_Click(objectsender,EventArgse){intn=0;n++;this.Insert(n,this.nam...
protected void Button1_Click(object sender, EventArgs e)
{
int n = 0; n++;
this.Insert(n, this.name.Text, this.address.Text, this.password.Text, this.bank.Text, this.account.Text, this.mgr.Text);
}
protected void Insert(int n, string name, string address, string password, string bank, string account, string mgr)
{
using (SqlConnection sqlconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ToString()))
{
string sql = "inset into Client(Client_name,Client_adderss,Client_password,Client_bank,Client_account,Client_mgr) values(" + name + "," + address + "," + password + "," + bank + "," + account + "," + mgr + "')";
sqlconnection.Open();
SqlCommand sqlcommand = new SqlCommand(sql, sqlconnection);
sqlcommand.ExecuteNonQuery();
Response.Write("<script>alert('Insert ok!');</script>");
}
} 展开
{
int n = 0; n++;
this.Insert(n, this.name.Text, this.address.Text, this.password.Text, this.bank.Text, this.account.Text, this.mgr.Text);
}
protected void Insert(int n, string name, string address, string password, string bank, string account, string mgr)
{
using (SqlConnection sqlconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ToString()))
{
string sql = "inset into Client(Client_name,Client_adderss,Client_password,Client_bank,Client_account,Client_mgr) values(" + name + "," + address + "," + password + "," + bank + "," + account + "," + mgr + "')";
sqlconnection.Open();
SqlCommand sqlcommand = new SqlCommand(sql, sqlconnection);
sqlcommand.ExecuteNonQuery();
Response.Write("<script>alert('Insert ok!');</script>");
}
} 展开
1个回答
2015-12-13
展开全部
是insert不是inset,另外文本型值外面要加一对单引号。
改成:
string sql = "insert into Client(Client_name,Client_adderss,Client_password,Client_bank,Client_account,Client_mgr) values('" + name + "','" + address + "','" + password + "','" + bank + "','" + account + "','" + mgr + "')";
改成:
string sql = "insert into Client(Client_name,Client_adderss,Client_password,Client_bank,Client_account,Client_mgr) values('" + name + "','" + address + "','" + password + "','" + bank + "','" + account + "','" + mgr + "')";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询