VB.NET 的ACCESS数据库操作问题,修改字段名
现有代码如下,VB.NET连接ACCESS2007数据库并在表DBMSG中添加列名为TextBox1内输入文本的字段:'连接数据库DimoCONAsOleDbConnec...
现有代码如下,VB.NET连接ACCESS2007数据库并在表DBMSG中添加列名为TextBox1内输入文本的字段:
'连接数据库
Dim oCON As OleDbConnection
Dim ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;persist Security Info =False;Data source=C:\AA.accdb;Jet OLEDB:Database Password=123456"
Try
oCON = New OleDbConnection(ConnStr)
oCON.Open()
Catch ex As Exception
MsgBox("网络错误!" & vbCrLf & "错误编号:" & Err.Number)
Me.Close()
End Try
'修改数据库
Dim oCMD As OleDbCommand
Dim oDS As New DataSet
Dim sql As String = "Alter Table DBMSG Add " & Trim(TextBox1.Text) & " Text"
Try
oCMD = New OleDbCommand(sql, oCON)
oCMD.ExecuteNonQuery()
MsgBox("修改成功!")
Catch ex As Exception
MsgBox("修改失败!" & vbCrLf & ex.Message)
Me.Close()
End Try
以上代码运行正常,但现在需要的是,除了添加列以外,如何修改列名(列标题)?
删除列我自己会,
sql =“Alter Table DBMSG Drop Column " & TextBox1.Text
就搞定了,现在就是没办法改列名,求助高人指点,万分感谢! 展开
'连接数据库
Dim oCON As OleDbConnection
Dim ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;persist Security Info =False;Data source=C:\AA.accdb;Jet OLEDB:Database Password=123456"
Try
oCON = New OleDbConnection(ConnStr)
oCON.Open()
Catch ex As Exception
MsgBox("网络错误!" & vbCrLf & "错误编号:" & Err.Number)
Me.Close()
End Try
'修改数据库
Dim oCMD As OleDbCommand
Dim oDS As New DataSet
Dim sql As String = "Alter Table DBMSG Add " & Trim(TextBox1.Text) & " Text"
Try
oCMD = New OleDbCommand(sql, oCON)
oCMD.ExecuteNonQuery()
MsgBox("修改成功!")
Catch ex As Exception
MsgBox("修改失败!" & vbCrLf & ex.Message)
Me.Close()
End Try
以上代码运行正常,但现在需要的是,除了添加列以外,如何修改列名(列标题)?
删除列我自己会,
sql =“Alter Table DBMSG Drop Column " & TextBox1.Text
就搞定了,现在就是没办法改列名,求助高人指点,万分感谢! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询