LEVEL子句包括拼写错误或缺失的保留字或参数,或者标点符号不正确的vb.net

时间:2016-03-23 16:25:10

标签: vb.net

 Dim connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Users\vladut.moraru\Desktop\TCO Orders\02_Template_BOM.xls;Extended Properties=""Excel 8.0;HDR=YES;"""

                Dim pram As OleDbParameter
                Dim dr As DataRow
                Dim olecon As OleDbConnection
                Dim olecomm As OleDbCommand
                Dim olecomm1 As OleDbCommand
                Dim oleadpt As OleDbDataAdapter
                Dim ds As DataSet
                Try
                    olecon = New OleDbConnection
                    olecon.ConnectionString = connstring
                    olecomm = New OleDbCommand
                    olecomm.CommandText = "Select Level, F_N, Name, Rev from [BOM$]"
                    olecomm.Connection = olecon
                    olecomm1 = New OleDbCommand
                    olecomm1.CommandText = "Insert into [BOM$] " & "(Level, F_N, Name, Rev) values " & "(@FName, @LName, @Age, @Phone)"
                    olecomm1.Connection = olecon
                    pram = olecomm1.Parameters.Add("@FName", OleDbType.VarChar)
                    pram.SourceColumn = "Level"
                    pram = olecomm1.Parameters.Add("@LName", OleDbType.VarChar)
                    pram.SourceColumn = "F_N"
                    pram = olecomm1.Parameters.Add("@Age", OleDbType.VarChar)
                    pram.SourceColumn = "Name"
                    pram = olecomm1.Parameters.Add("@Phone", OleDbType.VarChar)
                    pram.SourceColumn = "Rev"
                    oleadpt = New OleDbDataAdapter(olecomm)
                    ds = New DataSet
                    olecon.Open()
                    oleadpt.Fill(ds, "BOM")
                    If IsNothing(ds) = False Then
                        dr = ds.Tables(0).NewRow
                        dr("Level") = "Raman"
                        dr("F_N") = "Tayal"
                        dr("Name") = 24
                        dr("Rev") = 98989898
                        ds.Tables(0).Rows.Add(dr)
                        oleadpt = New OleDbDataAdapter
                        oleadpt.InsertCommand = olecomm1
                        Dim i As Integer = oleadpt.Update(ds, "BOM")
                    End If
                Catch ex As Exception

                Finally
                    olecon.Close()
                    olecon = Nothing
                    olecomm = Nothing
                    oleadpt = Nothing
                    ds = Nothing
                    dr = Nothing
                    pram = Nothing
                End Try

我希望使用列Level,F_N,Name,Rev写入tamplate excel,我的代码会从title中生成该错误。我想在我的excel中插入一些值但是在线oleadpt.Fill(ds,“BOM”)给我那个错误。我用excel文件放了一张照片。工作表名称为BOM

enter image description here

我的问题是,我错过了生成该代码的地方?我写错了我的专栏或我的连接?

0 个答案:

没有答案