日期:2014-05-19  浏览次数:20414 次

大家帮我看看这个SQL语句有什么语法错误??
"INSERT   INTO   User   (User_Name,   Password,   Name,   sex,   Email,   QICQ,   Address,   HomePage,   Job,   Phone,   Birthday,   Memos)   VALUES   ( ' "   +   tbUser.Text   +   " ', ' "   +   tbPwd.Text   +   " ', ' "   +   tbName.Text   +   " ', "   +Convert.ToInt32(   rbSex.SelectedItem.Value)   +   ", ' "   +   tbMail.Text   +   " ', ' "   +   tbQQ.Text   +   " ', ' "   +   tbAddr.Text   +   " ', ' "   +   tbUrl.Text   +   " ', ' "   +   tbJob.Text   +   " ', ' "   +   tbPhone.Text   +   " ', "   +   tbBirth.Text   +   ", ' "   +   tbOther.Text   +   " ') "

sex为radiobuttonlist,value为1和0,数据库中为int型;Birthday为日期型,其他均为varchar类型!!
大家帮帮忙,好长时间没有解决的问题!!
拜托!!

------解决方案--------------------
, " +Convert.ToInt32( rbSex.SelectedItem.Value) + ",
楼上的提示是对的,可惜原因是错误的,你这里+运算符是字符串拼接的,结果到这里你转换为了int型,这个肯定不对,不用转换了,加个ToString();
------解决方案--------------------
protected void BtnPost_Click(object sender, EventArgs e)
{
if (Db.img( "INSERT INTO [User] (User_Name, Password, Name, sex, Email, QICQ, Address, HomePage, Job, Phone, Birthday, Memos) VALUES ( ' " + tbUser.Text + " ', ' " + tbPwd.Text + " ', ' " + tbName.Text + " ', ' "+ (Convert.ToInt32( rbSex.SelectedItem.Value )).ToString()+ " ', ' " + tbMail.Text + " ', ' " + tbQQ.Text + " ', ' " + tbAddr.Text + " ', ' " + tbUrl.Text + " ', ' " + tbJob.Text + " ', ' " + tbPhone.Text + " ', ' " + tbBirth.Text + " ', ' " + tbOther.Text + " ') "))
{
Response.Redirect( "Regist_succeed.aspx ");
}
else
{
Response.Redirect( "Regist_fail.aspx ");
}
}

-------
User是SQL的關鍵字,前後加上[]試下