qq_37708997
2020-08-02 15:03
采纳率: 25%
浏览 86

SQL数据库改成ACC数据库

VB.net
需要用到这段代码,但原码是SQL数据连接,本人用的是ACC,请帮忙改下换成ACC数据连接方式。谢谢!

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
    Dim oldno As String = Session("oldNo").ToString
    Dim a As TextBox = GridView1.Rows(e.RowIndex).Cells(1).Controls(0)
    Dim currno As String = a.Text
    Dim b As TextBox = GridView1.Rows(e.RowIndex).Cells(2).Controls(0)
    Dim currname As String = b.Text
    Dim Conn As New SqlConnection
    Conn.ConnectionString = "Server=.;Uid=sa;Pwd=123;Database= StuManage"
    Conn.Open()
    Dim comm As New SqlCommand
    comm.Connection = Conn
    comm.CommandType = Data.CommandType.Text
    comm.CommandText = "update class set clsNo=@clsNo,clsName=@clsName where clsNo=@oldno"
    comm.Parameters.AddWithValue("@clsNo", currno)
    comm.Parameters.AddWithValue("@clsName", currname)
    comm.Parameters.AddWithValue("@oldno", oldno)
    Try
        comm.ExecuteNonQuery()
    Catch ex As Exception
        MsgBox(Err.Description, MsgBoxStyle.Information)
    End Try
    Conn.Close()
    GridView1.EditIndex = -1
    GridRefesh()
End Sub
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • jingluan666 2020-08-02 15:09
    已采纳
    点赞 打赏 评论
  • SqlConnection
    SqlCommand
    等全部修改为
    OleDbConnection
    QleDbCommand
    
    把
    Imports System.Data.SQLClient
    修改为
    Imports System.Data.OleDb
    
    Conn.ConnectionString = "Server=.;Uid=sa;Pwd=123;Database= StuManage"
    修改为
    Conn.ConnectionString = "Provider=Microsoft.Ace.OleDb.12.0;" & "Data Source=X:\路径\access数据库文件名.accdb;" & "Persist Security Info=False;"
    
    点赞 打赏 评论

相关推荐