当前位置: 代码迷 >> Sql Server >> 帮看几条SQL语句,标点符号有点有关问题
  详细解决方案

帮看几条SQL语句,标点符号有点有关问题

热度:74   发布时间:2016-04-27 11:13:17.0
帮看几条SQL语句,标点符号有点问题
C# code
 protected void Button1_Click(object sender, EventArgs e)        {            //int X = Convert.ToInt32(Request.QueryString["tablename"]);            int countjieguo = tongjibiao();            int X = countjieguo - 2;             //要减去系统必须的3个表                        bool isexistbiao = isexist("table"+X.ToString());            if (isexistbiao == false)            {                string sqlstr = "create table table'" + X + "' (id int identity not null,title nvarchar(100),username nvarchar(100),time datetime,content ntext,class nvarchar(100))";                sqlEx(sqlstr);               //string strupdate = "insert into table'" + X.ToString() + "' (title,username,time,content) values ('" + TextBox4.Text.ToString() + "' , " + "' 1 '" + " ,'" + DateTime.Now + "', '" + TextBox1.Text.ToString() + "')";               //sqlEx(strupdate);                MessageBox.Show("发帖成功!");            }            else            {                MessageBox.Show("发帖失败,请重试!");            }         }


提示table附近有语法错误

------解决方案--------------------
你既然上面isexist判断的是"table"+X.ToString(),那下面的query直接"create table table"+X+" (id..."就可以了。另外单引号'不能当做表名的一部分。
------解决方案--------------------
string sqlstr = "create table table'" + X + "' (id int identity not null,title 
此句的 '" + X + "' 單引號不要,X應該先轉成string 再加
------解决方案--------------------
SQL code
string sqlstr = "create table table'" + X + "' (id int identity not null,title nvarchar(100),username nvarchar(100),time datetime,content ntext,class nvarchar(100))";--这一句中创建表 create table table'是不合法的
------解决方案--------------------
"create table table" + X + "
没有table'7'这样的名字。
 去掉引号要么
"create table [table'" + X + "']..