这是我的代码  期待高手解决 啊
 
public void newyh(string zh)//注册新用户
    {
        SqlConnection conn = new SqlConnection(connStr);
        string sqnb = "create table' "+zh+" '(id int  not null,消息 nvarchar(50) not null)";
        SqlCommand cmdb = new SqlCommand(sqnb, conn);
        
        conn.Open();
        cmdb.ExecuteNonQuery();   //这句出错·
        conn.Close();
             
    }

解决方案 »

  1.   

    string sqnb = "create table "+zh+" (id int  not null,消息 nvarchar(50) not null)"; 
    sqnb =string.Format("create table {0}(id int  not null,消息 nvarchar(50) not null)",zh);
      

  2.   

    string sqnb = "create table "+zh+" (id int  not null,消息 nvarchar(50) not null)"; 
      

  3.   

    应该是这条语句出错了:string sqnb = "create table' "+zh+" '(id int  not null,消息 nvarchar(50) not null)";
    创建一个表应该不是这样的吧?真不好意思,帮不了你 
      

  4.   

     string tName = "zh";
     string sql = "create table " + tName + " (id int not null,消息 nvarchar(50) not null)";这样可以了,‘" + tName + "’把这个单引号去了就可以了。