2017-06-22 86 views
-1

我的目標:使用visual basic向mysql數據庫添加一列!如何使用visual basic將列添加到mysql數據庫

我已經嘗試了多種方法,但這裏是我目前使用的代碼:

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click 
    MysqlConn = New MySqlConnection 
    MysqlConn.ConnectionString = "Server=xxx.xx.xxx.xxx;Port=3306;Database=test;Uid=tester;Pwd=***" 
    Try 
     MysqlConn.Open() 
     Dim Query As String 
     Query = "ALTER TABLE user ADD test INT NOT NULL" 
     COMMAND = New MySqlCommand(Query, MysqlConn) 
     MysqlConn.Close() 
    Catch ex As Exception 
    End Try 
End Sub 

我認爲這是與查詢的問題!感謝您的幫助! 這與ms sql不同,它是可視化的基礎。

+1

[將NOT NULL列插入到現有表中](https://stackoverflow.com/questions/3492947/insert-a-not-null-column-to -an-existing-table) – kielou

+0

該鏈接不能幫助我,我已經嘗試了頁面上的所有內容,沒有任何工作。我想要一個在visual basic中非空列的例子。 –

回答

0

我的視覺工作室實際上並沒有使用我最新的代碼,現在一切都在工作LOL。這裏是我修改後的代碼:
MysqlConn = New MySqlConnection MysqlConn.ConnectionString = "Server=**.**.***.***;Port=3306;Database=test;Uid=tester;Pwd=***" Dim READER As MySqlDataReader Try MysqlConn.Open() Dim Query As String Query = "alter table test.user add test int not null" COMMAND = New MySqlCommand(Query, MysqlConn) READER = COMMAND.ExecuteReader MysqlConn.Close() Catch ex As Exception End Try

相關問題