asp.net 编译后按下BUTTON sqlcmd.ExecuteNonQuery(); 出现 [ Incorrect syntax near 'vaules'.]是怎么回
usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingSystem.W...
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class UseExecuteNonQuery:System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
string strA = Textbox1.Text.ToString();
string strB = Textbox2.Text.ToString();
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "Data Source=.;uid=sa;pwd=1234567; Initial Catalog=Test; ";
sqlcon.Open();
string strInsert = string.Format("insert into uuu(user_name,user_password) vaules('{0}','{1}')", strA, strB);
SqlCommand sqlcmd = new SqlCommand(strInsert, sqlcon);
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
Label1.Text = "OK";
}
}
sqlcmd.ExecuteNonQuery(); 出现 [ Incorrect syntax near 'vaules'.]报错 展开
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class UseExecuteNonQuery:System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
string strA = Textbox1.Text.ToString();
string strB = Textbox2.Text.ToString();
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "Data Source=.;uid=sa;pwd=1234567; Initial Catalog=Test; ";
sqlcon.Open();
string strInsert = string.Format("insert into uuu(user_name,user_password) vaules('{0}','{1}')", strA, strB);
SqlCommand sqlcmd = new SqlCommand(strInsert, sqlcon);
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
Label1.Text = "OK";
}
}
sqlcmd.ExecuteNonQuery(); 出现 [ Incorrect syntax near 'vaules'.]报错 展开
3个回答
展开全部
sqlcmd.ExecuteNonQuery(); 我觉得你在编程序之前最好要弄明白方法的用途。就如本例中sqlcommand命令的ExecuteNonQuery()方法用于执行指定的SQL语句,如增、删、改,它返回的是受SQL语句影响的行数。
所以必须定义一个变量来接受ExecuteNonQuery()方法的返回值,是个整型变量
int result =sqlcmd.ExecuteNonQuery();
[ Incorrect syntax near 'vaules'.]的意思是:不正确的句法结构附近没有返回值
所以必须定义一个变量来接受ExecuteNonQuery()方法的返回值,是个整型变量
int result =sqlcmd.ExecuteNonQuery();
[ Incorrect syntax near 'vaules'.]的意思是:不正确的句法结构附近没有返回值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string strA = Textbox1.Text.ToString();
string strB = Textbox2.Text.ToString();
文本框本来就是字符串的·你还转换干嘛...
string strB = Textbox2.Text.ToString();
文本框本来就是字符串的·你还转换干嘛...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询