无法执行任何oledb命令

时间:2017-09-30 22:03:05

标签: vb.net

我正在使用vb.net和访问进行考试座位安排的项目。 但是我不会执行任何插入或检索等任何查询。每当我尝试这样做时我会得到一个错误,说方法或操作没有实现。这是我的代码......

Imports System.Data.OleDb

Public Class form4
    'global declarations'
    Dim constring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Acer\Documents\Exam.accdb"
    Dim conn As New OleDbconnection(constring)
    Dim adapter As OleDbdataadapter
    Dim dt As New DataTable()
    Dim cmd As OleDbCommand
    'inserting into db'
    Private Sub add()

        Dim sql As String = "INSERT INTO Tclassroom(Room no,Capacity) VALUES(@Room,@Capacity)"
        cmd = New OleDbCommand(sql, conn)
        cmd.parameters.addwithvalue("@Room", TextBox2.Text)
        cmd.parameters.addwithvalue("@Capacity", TextBox3.Text)
        Try
            If cmd.executenonquery() > 0 Then
                MsgBox("Successfully inserted")
                retrieve()
                cleartxt()
            End If
            conn.close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
提前thnkzz ... enter image description here

0 个答案:

没有答案