标准表达式中数据类型不匹配。int insert = Convert.ToInt32(mycmd.ExecuteNonQuery()); 报错 哪位大虾帮
stringsettings=ConfigurationManager.AppSettings["SQLConnString"].ToString()+Server.Ma...
string settings = ConfigurationManager.AppSettings["SQLConnString"].ToString() + Server.MapPath(ConfigurationManager.AppSettings["dbPath"]) + ";";
OleDbConnection myconn = new OleDbConnection(settings);
myconn.Open();
string strsql = "insert into news(newstitle,newsneirong,addtime,username) value (" + this.TextBoxnewstitle.Text.ToString() + "," + this.TextBoxnewsneirong.Text.ToString() + ",getdate()," + username + ")";
OleDbCommand mycmd = new OleDbCommand(strsql, myconn);
int insert = Convert.ToInt32(mycmd.ExecuteNonQuery());
string settings = ConfigurationManager.AppSettings["SQLConnString"].ToString() + Server.MapPath(ConfigurationManager.AppSettings["userPath"]) + ";";
OleDbConnection myconn = new OleDbConnection(settings);
myconn.Open();
OleDbParameter username = new OleDbParameter(this.TextBoxusername.Text.ToString(), OleDbType.VarWChar, 100);
OleDbParameter userpassword = new OleDbParameter(this.TextBoxusername.Text.ToString(), OleDbType.VarWChar, 100);
string sqlstr = "select count(*) from [user] where username=" + username + " and userpassword=" + userpassword + "";
OleDbCommand mycmd = new OleDbCommand(sqlstr, myconn);//创建数据库命令
int count = Convert.ToInt32(mycmd.ExecuteScalar().ToString ()); 展开
OleDbConnection myconn = new OleDbConnection(settings);
myconn.Open();
string strsql = "insert into news(newstitle,newsneirong,addtime,username) value (" + this.TextBoxnewstitle.Text.ToString() + "," + this.TextBoxnewsneirong.Text.ToString() + ",getdate()," + username + ")";
OleDbCommand mycmd = new OleDbCommand(strsql, myconn);
int insert = Convert.ToInt32(mycmd.ExecuteNonQuery());
string settings = ConfigurationManager.AppSettings["SQLConnString"].ToString() + Server.MapPath(ConfigurationManager.AppSettings["userPath"]) + ";";
OleDbConnection myconn = new OleDbConnection(settings);
myconn.Open();
OleDbParameter username = new OleDbParameter(this.TextBoxusername.Text.ToString(), OleDbType.VarWChar, 100);
OleDbParameter userpassword = new OleDbParameter(this.TextBoxusername.Text.ToString(), OleDbType.VarWChar, 100);
string sqlstr = "select count(*) from [user] where username=" + username + " and userpassword=" + userpassword + "";
OleDbCommand mycmd = new OleDbCommand(sqlstr, myconn);//创建数据库命令
int count = Convert.ToInt32(mycmd.ExecuteScalar().ToString ()); 展开
3个回答
展开全部
mycmd.ExecuteNonQuery()的返回值就是INT型,把 Convert.ToInt32去掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把“int insert = Convert.ToInt32(mycmd.ExecuteNonQuery());“替换为"try{int insert = Convert.ToInt32(mycmd.ExecuteNonQuery());}catch{int insert=0;}"
下面的count同理。。。。
下面的count同理。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ExecuteNonQuery 方法本身就返回int 类型 你为什么还要转换类型呢?
更多追问追答
追问
int count = Convert.ToInt32(mycmd.ExecuteScalar().ToString ()); 这个也说不匹配 怎么能啊
这个是输入账号跟密码登录时提示的错误 判断是否在数据库中有数据
追答
你把后面的toString 去掉
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询