连到相应的数据库, 执行 create table xxx (xxxxxxx) 建表语句??

解决方案 »

  1.   

    SqlConnection _connection= new SqlConnection("server=(local);database=pub;Integrated Security=SSPI");
    SqlCommand myCommand = new SqlCommand("create table table1(fielea int,fieldb char 4), _connection);myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();
    myCommand.Connection.Close();就能建议一个表table1
      

  2.   

    SqlCommand myCommand = new SqlCommand("create table table1(fielea int,fieldb char 4), _connection);
    ==>
    SqlCommand myCommand = new SqlCommand("create table table1(fielea int,fieldb char (4))", _connection);database=pub  
    ==>
    database=pubs (^_^你自己还应该别改)
      

  3.   

    就像楼上几位那样,通过用Command命令执行sql语句就能够创建数据库的各种对象啊。创建完毕之后就可以看到的。
    不知道楼主的意思是否如此?
      

  4.   

    对不起啊,是这样,我没叙述清楚
    我想使客户在使用时动态的输入数据表的名称
    但是如果使用SQL命令,其命令行是被双隐号括起来的,传进来的变量名也就不能按它的值来构造表了,有方法可以改进吗
    使用存储过程也不可以,我试过了
      

  5.   

    看一下Sql server建表是要选择的东西。
    然后在C#中填加对应的选项。生成Sql语句,执行。
      

  6.   

    改进,设:用户输入要求的表名为sCustomTableName:string sCustomCreateTable = string.Format("CREATE TABLE {0} (fielea int,fieldb char (4))", sCustomTableName);
    SqlCommand myCommand = new SqlCommand(sCustomCreateTable, _connection);