(VB.NET)语法错误在INSERT INTO语句 - Microsoft Jet数据库引擎 [英] (VB.NET)Syntax Error in INSERT INTO statement - MICROSOFT JET DATABASE ENGINE

查看:371
本文介绍了(VB.NET)语法错误在INSERT INTO语句 - Microsoft Jet数据库引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,我开发了一个简单的Access数据库,并创建一个VB的.Net用户界面。 我无法将数据插入到表,这里是我的样品code ......我只是一个初学者在VB.Net我希望你能帮助我这一个

 昏暗CON作为新的OleDbConnection
    DIM在cmd作为新的OleDbCommand
    昏暗的大作为新OleDbDataAdapter的
    昏暗的DS作为新的数据集
    昏暗博士担任的DataRow


    con.ConnectionString =供应商= Microsoft.Jet.OLEDB.4.0;数据源= C:\ Documents和Settings \测试\桌面\ Privilege.Net \ PrivilegeCar​​d \数据库\ dbPrivilegeSystem.mdb

    cmd.CommandText =SELECT * FROM向tblUsers;

    尝试
        con.Open()
        cmd.Connection = CON

        cmd.CommandType = CommandType.Text

        da.SelectCommand = CMD
        da.Fill(DS,向tblUsers)

        博士= ds.Tables(向tblUsers)。NEWROW


        System.Convert.ToDateTime(dtPicker.Value).ToOADate()
        我一直在试图使用该转换日期思维,如果这能帮助我解决我的问题

        博士(0)= txtUserN.Text
        博士(1)= txtPass.Text
        博士(2)= txtAccess.Text
        博士(3)= dtPicker.Value
        博士(4)= txtName.Text
        博士(5)= txtPos.Text
        博士(6)= cmbDept.Text

        ds.Tables(向tblUsers)。行()。添加(DR)

        昏暗的CB作为新OleDbCommandBuilder(DA)

        da.Fill(DS)
        da.Update(DS,向tblUsers)

    抓住EX作为OleDbException

        的MessageBox.show(ex.Message&安培; - &安培; ex.Source)
    结束尝试
 

解决方案

看看我的code,这是easer

 进口System.Data这
部分类theClassName
    继承System.Web.UI.Page
保护小组Button_Click(BYVAL发件人为对象,BYVALË作为System.EventArgs)把手Button.Click
昏暗的connectionString作为字符串=供应商= Microsoft.Jet.OLEDB.4.0; OLEDB服务= -4;数据源=&放大器; MapPath的(〜/ App_Data文件)及/database.mdb
        昏暗的DBConnection的作为System.Data.IDbConnection =新System.Data.OleDb.OleDbConnection(的connectionString)
        昏暗查询字符串作为字符串=INSERT INTO [客户]([ID],[名],[地址] [电话],[DATE_OF_BIRTH],[民族],[room_no],[NUMBER_OF_DAYS)值(与& txtid的.text&安培;,与& txtname.Text&安培;','与& txtaddress.Text&安培;',&安培; txtphone.Text&安培;,&安培; txtdate.Text&安培;, '与&&txtnation.Text安培;',&安培; txtroom.Text&安培;,&安培; txtday.Text&安培;)
        昏暗的DbCommand作为System.Data.IDbCommand =新System.Data.OleDb.OleDbCommand
        dbcommand.CommandText = QUERYSTRING
        dbcommand.Connection = DBConnection进行
        dbconnection.Open()
        昏暗的RowsAffected为整数= 0

        尝试
            的RowsAffected = dbcommand.ExecuteNonQuery
            result.Text =记录保存
        抓住
            result.Text =记录不保存
        最后
            dbconnection.Close()
        结束尝试

           结束小组
 末级
 

I need help, I developed a simple Access database and I create a VB .Net user interface. I can't INSERT data into the Table here's my sample code... I'm only a beginner in VB.Net i hope you could help me with this one

Dim con As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim da As New OleDbDataAdapter
    Dim ds As New DataSet
    Dim dr As DataRow


    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Test\Desktop\Privilege.Net\PrivilegeCard\Database\dbPrivilegeSystem.mdb"

    cmd.CommandText = "Select * From tblUsers;"

    Try
        con.Open()
        cmd.Connection = con

        cmd.CommandType = CommandType.Text

        da.SelectCommand = cmd
        da.Fill(ds, "tblUsers")

        dr = ds.Tables("tblUsers").NewRow


        'System.Convert.ToDateTime(dtPicker.Value).ToOADate()
        'I've been trying to use this conversion for date thinking if this could help me fix my problem

        dr(0) = txtUserN.Text
        dr(1) = txtPass.Text
        dr(2) = txtAccess.Text
        dr(3) = dtPicker.Value
        dr(4) = txtName.Text
        dr(5) = txtPos.Text
        dr(6) = cmbDept.Text

        ds.Tables("tblUsers").Rows().Add(dr)

        Dim cb As New OleDbCommandBuilder(da)

        da.Fill(ds)
        da.Update(ds, "tblUsers")

    Catch ex As OleDbException

        MessageBox.Show(ex.Message & " - " & ex.Source)
    End Try

解决方案

take a look at my code ,it is easer

Imports System.Data
Partial Class theClassName
    Inherits System.Web.UI.Page
Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.Click
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & MapPath("~/App_Data") & "/database.mdb"
        Dim dbconnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
        Dim queryString As String = "Insert into [customer] ([ID],[name],[address],[phone],[date_of_birth],[Nationality],[room_no],[number_of_days]) Values (" & txtid.Text & ", '" & txtname.Text & "', '" & txtaddress.Text & "', " & txtphone.Text & ", " & txtdate.Text & ", '" & txtnation.Text & "'," & txtroom.Text & "," & txtday.Text & ")"
        Dim dbcommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbcommand.CommandText = queryString
        dbcommand.Connection = dbconnection
        dbconnection.Open()
        Dim rowsAffected As Integer = 0

        Try
            rowsAffected = dbcommand.ExecuteNonQuery
            result.Text = "Record Saved"
        Catch
            result.Text = "Record not saved"
        Finally
            dbconnection.Close()
        End Try

           End Sub
 End Class

这篇关于(VB.NET)语法错误在INSERT INTO语句 - Microsoft Jet数据库引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆