ASP.NET数据库连接
stringsettings=Convert.ToString(ConfigurationManager.ConnectionStrings["newsBiomensCo...
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["newsBiomensConn"]); //读取数据库连接字符串
OleDbConnection myconn = new OleDbConnection(settings); //创建数据库连接对象
myconn.Open(); //打开数据库连接
//创建SQL语句
string account = tbAccount.Text;
string psw = tbRepwd.Text;
string name = tbName.Text;
string sex = rblSex.Text.ToString();
string card = tbIDcard.Text;
string answer = tbAnswer.Text;
DateTime newsDate = DateTime.Now;
string strsql = "insert into Users(UserAccount,Password,UserName,UserSex,IDcard,Answer,UserAddData) values (";
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
//创建数据库命令
OleDbCommand mycmd = new OleDbCommand(strsql, myconn);
//测试语句
//Response.Write(strsql);
//Response.End();
mycmd.ExecuteNonQuery();
//关闭数据库
myconn.Close();
报错说是inert into语法错误 展开
OleDbConnection myconn = new OleDbConnection(settings); //创建数据库连接对象
myconn.Open(); //打开数据库连接
//创建SQL语句
string account = tbAccount.Text;
string psw = tbRepwd.Text;
string name = tbName.Text;
string sex = rblSex.Text.ToString();
string card = tbIDcard.Text;
string answer = tbAnswer.Text;
DateTime newsDate = DateTime.Now;
string strsql = "insert into Users(UserAccount,Password,UserName,UserSex,IDcard,Answer,UserAddData) values (";
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
//创建数据库命令
OleDbCommand mycmd = new OleDbCommand(strsql, myconn);
//测试语句
//Response.Write(strsql);
//Response.End();
mycmd.ExecuteNonQuery();
//关闭数据库
myconn.Close();
报错说是inert into语法错误 展开
1个回答
展开全部
string strsql = "insert into Users(UserAccount,Password,UserName,UserSex,IDcard,Answer,UserAddData) values (";
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
改成
string strsql = "insert into [Users]([UserAccount],[Password],[UserName],[UserSex],[IDcard],[Answer],[UserAddData]) values (";
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
里面的password是保留字不可直接使用,其它的也许也有保留字,于是全部都给它加上[]
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
改成
string strsql = "insert into [Users]([UserAccount],[Password],[UserName],[UserSex],[IDcard],[Answer],[UserAddData]) values (";
strsql = strsql + "'" + account + "','" + psw + "','" + name + "','" + sex + "','" + card + "','" + answer + "','" + newsDate + "')";
里面的password是保留字不可直接使用,其它的也许也有保留字,于是全部都给它加上[]
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询