建議在createtable中加一句"if exists(select * from teacher) drop table teacher"

解决方案 »

  1.   

    最好try,catch一下,这样的问题一般是楼上说的,要么就是表已经存在,要不就是连接失败也就是断掉了,呵呵,try一下可以看到更详细的错误信息
      

  2.   

    System.Data.SqlClient.SqlCommand newCommand=new SqlCommand(createtable,sqlConnection);
      

  3.   

    这样写,你的错误太多了string myConnectionString = "data source=HK-RUANLEI;initial catalog=qqqq;integrated security=SSPI;persist security info=False;workstation id=HK-RUANLEI;packet size=4096";
    string createtable="CREATE TABLE teacher(qq CHAR(5)NOT NULL UNIQUE, aa CHAR(20)UNIQUE, bb CHAR(1))";
    SqlConnection MyConnection = new SqlConnection(myConnectionString);
    SqlCommand myCommand = new SqlCommand();
    myConnection.Open();
    myCommand.Connection = MyConnection;
    myCommand.CommandText = createtable;
    myCommand.ExecuteNonQuery();
    myCommand.Dispose();
    myConnection.Close();
    myConnection.Dispose();
    PS:你的SQL语句我没检查