数据库变量问题!!!急!!!在线等!!!
DAOHelper.ExecuteNonQuery( "insert into users(username,userpassword,useremail,usename,sex,regdate,ip) values( ' "+this.username.Text.Trim()+ " ', ' "+this.password.Text.Trim()+ " ', ' "+this.useremail.Text.Trim()+ " ', ' "+this.usename.Text.Trim()+ " ',@selsex,@thistime,@thisip) ");
请问这个插入语句,其实@的是变量!!怎么改呀...?怎么把变量的值插进去呢?????
大家帮帮!!!!好急呀!!
------解决方案--------------------DAOHelper.ExecuteNonQuery(string.Format( "insert into users(username,userpassword,useremail,usename,sex,regdate,ip) values( '{0} ', '{1} ', '{2} ', '{4} ',{5},{6},{7}) ",this.username.Text.Trim(),this.password.Text.Trim(),this.useremail.Text.Trim(),this.usename.Text.Trim(),@selsex,@thistime,@thisip);
----------------------
这样写清楚点。。。你的变量怎么用@开头啊,这又不是声明SQL变量
------解决方案--------------------SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter( "@selsex ", SqlDbType.NVarchar, 1),
new SqlParameter( "@thistime ", SqlDbType.Date),
new SqlParameter( "@thisip ", SqlDbType.Char, 8),
};
执行的时候,把参数写上就可以了