INSERT INTO语法错误

时间:2014-07-16 13:48:15

标签: excel vb.net ado.net oledb

通过单击将3文本框保存在Excel文件中的保存按钮,我遇到了此错误。 我设法在datagridview中显示excel文件的内容......但是我无法通过OleDBCommanBuilder保存数据。 为了任何有用的目的,它加入了代码:

Imports System
Imports System.Data.OleDb
Public Class Form1
    Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; data source=D:\Users\mghazlan\Desktop\doss\DB.xls; Extended Properties=Excel 8.0;")
    Dim cmd As OleDbCommand = New OleDbCommand("", con)
    Dim da As OleDbDataAdapter = New OleDbDataAdapter()
    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder()
    Dim ds As New DataSet()

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    cmd.CommandText = "select * from [Feuil$]"
    da = New OleDbDataAdapter(cmd)
    builder = New OleDbCommandBuilder(da)
    da.Fill(ds, "Feuil")
    DataGridView1.DataSource = ds.Tables("Feuil")


    ' MessageBox.Show(con.State)



End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim ligne As DataRow = ds.Tables("Feuil").NewRow
    ligne("ID") = TextBox1.Text.ToString
    ligne("Nom") = TextBox2.Text.ToString
    ligne("Prenom") = TextBox3.Text.ToString

    ds.Tables("Feuil").Rows.Add(ligne)
    da.Update(ds, "Feuil")
    ds.AcceptChanges()
    MessageBox.Show("Ajouté avec Succès", "Succès", MessageBoxButtons.OK, 
MessageBoxIcon.Information)
    End Sub
End Class

0 个答案:

没有答案