cmd.ExecuteNonQuery(); INSERT INTO 语句的语法错误。
我用在Access数据库中用这句插入语句可以插入数据,但是在这里就报语法错误。代码如下:publicpartialclassregister:System.Web.UI....
我用在Access数据库中用这句插入语句可以插入数据,但是在这里就报语法错误。
代码如下:
public partial class register : System.Web.UI.Page
{
string str_cnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
string str_sourcefile = "App_Data\\DATA.mdb";
OleDbConnection cnn;
OleDbCommand cmd;
OleDbDataReader datar;
string str_sql;
protected void Button1_Click(object sender, EventArgs e)
{
string str_conn = str_cnn + MapPath(str_sourcefile);
cnn = new OleDbConnection(str_conn);
cnn.Open();
string _name, _pwd;
_name = txt_name.Text;
_pwd = txt_pwd.Text;
str_sql = "INSERT INTO user (user_name,user_pwd) values ('" + _name + "','" + _pwd + "')";
cmd = new OleDbCommand(str_sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
}
} 展开
代码如下:
public partial class register : System.Web.UI.Page
{
string str_cnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
string str_sourcefile = "App_Data\\DATA.mdb";
OleDbConnection cnn;
OleDbCommand cmd;
OleDbDataReader datar;
string str_sql;
protected void Button1_Click(object sender, EventArgs e)
{
string str_conn = str_cnn + MapPath(str_sourcefile);
cnn = new OleDbConnection(str_conn);
cnn.Open();
string _name, _pwd;
_name = txt_name.Text;
_pwd = txt_pwd.Text;
str_sql = "INSERT INTO user (user_name,user_pwd) values ('" + _name + "','" + _pwd + "')";
cmd = new OleDbCommand(str_sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
}
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询