如何按 ListBox 中的项目更改 Table 中的新列
How To ALTER New Columns In Table by Items from ListBox
我的数据库在 MS Access 2010 中运行完美,使用代码更改 Table 中的所有 ListBox
项目,这些项目由另一个 table 填充,用户代码如下:
Sub AlterTableX()
Dim intLoop As Integer
Dim strSQL As String
Dim strSQL1 As String
For intLoop = 0 To Me.field_row.ListCount - 1
strSQL = "ALTER TABLE Emp_Sal ADD " & _
Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
CurrentProject.Connection.Execute strSQL
strSQL1 = "ALTER TABLE tbl_General ADD " & _
Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
CurrentProject.Connection.Execute strSQL1
Next intLoop
' MsgBox "Success Adding Columns", vbOKOnly, "Success"
End Sub
嗯,现在我想将 VBA 代码转换为 VB.NET 2012
我需要你的帮助。
如果您只是想在 VB.NET 中执行相同的命令,请尝试这样的操作。它应该可以帮助您入门,但最好按照评论
中的建议阅读 ADO.NET
Using SqlCMD As New OleDb.OleDbCommand()
SqlCMD.Connection = CurrentProject.Connection
Try
SqlCMD.Connection.Open()
For intLoop As Integer = 0 To Me.field_row.ListCount - 1
SqlCMD.CommandText = "ALTER TABLE Emp_Sal ADD " & Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
SqlCMD.ExecuteNonQuery()
SqlCMD.CommandText = "ALTER TABLE tbl_General ADD " & Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
SqlCMD.ExecuteNonQuery()
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR ALTERING TABLE")
Finally
SqlCMD.Connection.Close()
End Try
End Using
我的数据库在 MS Access 2010 中运行完美,使用代码更改 Table 中的所有 ListBox
项目,这些项目由另一个 table 填充,用户代码如下:
Sub AlterTableX()
Dim intLoop As Integer
Dim strSQL As String
Dim strSQL1 As String
For intLoop = 0 To Me.field_row.ListCount - 1
strSQL = "ALTER TABLE Emp_Sal ADD " & _
Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
CurrentProject.Connection.Execute strSQL
strSQL1 = "ALTER TABLE tbl_General ADD " & _
Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
CurrentProject.Connection.Execute strSQL1
Next intLoop
' MsgBox "Success Adding Columns", vbOKOnly, "Success"
End Sub
嗯,现在我想将 VBA 代码转换为 VB.NET 2012
我需要你的帮助。
如果您只是想在 VB.NET 中执行相同的命令,请尝试这样的操作。它应该可以帮助您入门,但最好按照评论
中的建议阅读 ADO.NET Using SqlCMD As New OleDb.OleDbCommand()
SqlCMD.Connection = CurrentProject.Connection
Try
SqlCMD.Connection.Open()
For intLoop As Integer = 0 To Me.field_row.ListCount - 1
SqlCMD.CommandText = "ALTER TABLE Emp_Sal ADD " & Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
SqlCMD.ExecuteNonQuery()
SqlCMD.CommandText = "ALTER TABLE tbl_General ADD " & Me.field_row.Column(0, [intLoop]) & " LONG INTEGER"
SqlCMD.ExecuteNonQuery()
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR ALTERING TABLE")
Finally
SqlCMD.Connection.Close()
End Try
End Using