asp.net 添加数据
这段代码在插入日期的时候老是有错误我数据库里面的类型是日期类型,stringUsername=Request.Form["name"];stringContent=Req...
这段代码 在插入日期的时候老是有错误 我数据库里面的类型是日期类型,
string Username=Request.Form["name"];
string Content=Request.Form["content"];
string strDb="db.mdb";
DateTime pubdate=System.DateTime.Now.Date;
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath(strDb);
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand("insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"''"+pubdate+"')" , objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
我用的是 access 数据库 用asp.net 写的下面的sql 语句有什么问题啊,怎么老是错误
insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"',now()) 展开
string Username=Request.Form["name"];
string Content=Request.Form["content"];
string strDb="db.mdb";
DateTime pubdate=System.DateTime.Now.Date;
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath(strDb);
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand("insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"''"+pubdate+"')" , objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
我用的是 access 数据库 用asp.net 写的下面的sql 语句有什么问题啊,怎么老是错误
insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"',now()) 展开
2个回答
展开全部
string Username=Request.Form["name"];
string Content=Request.Form["content"];
string strDb="db.mdb";
DateTime pubdate=System.DateTime.Now.Date;
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath(strDb);
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand("insert into message(content,name,time)Values('"+Content+"','"+Username+"',#"+pubdate+"#)" , objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
string Content=Request.Form["content"];
string strDb="db.mdb";
DateTime pubdate=System.DateTime.Now.Date;
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath(strDb);
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand("insert into message(content,name,time)Values('"+Content+"','"+Username+"',#"+pubdate+"#)" , objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
展开全部
把OleDbCommand objCommand = new OleDbCommand("insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"''"+pubdate+"')" , objConnection);
换为
OleDbCommand objCommand = new OleDbCommand("insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"','"+pubdate+"')#" , objConnection+"#");
补存:
把 insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"',now())
改为
insert into message (content,name,time) Values ("'"+Content.ToString()+"','"+Username.ToString()+"',#now()#")
试试行不
换为
OleDbCommand objCommand = new OleDbCommand("insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"','"+pubdate+"')#" , objConnection+"#");
补存:
把 insert into message (content,name,time) Values ('"+Content.ToString()+"','"+Username.ToString()+"',now())
改为
insert into message (content,name,time) Values ("'"+Content.ToString()+"','"+Username.ToString()+"',#now()#")
试试行不
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询