Public Class Form1
Private Const connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=P:\Pdrive\Karnav\Test1.xlsx;Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;ImportMixedTypes=Text;"""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pram As OleDb.OleDbParameter
Dim olecon As OleDb.OleDbConnection
Dim olecomm As OleDb.OleDbCommand
Dim oleadpt As OleDb.OleDbDataAdapter
Dim ds As DataSet
Dim a As String
Dim b As String
Dim c As Date
Dim d As Date
Dim f As String
Dim g As String
Dim h As String
Dim i As String
Try
a = purchase.Text
b = ListBox3.Text
c = DateTimePicker1.Text
d = DateTimePicker2.Text
f = TextBox3.Text
g = ListBox1.Text
h = ListBox2.Text
i = TextBox4.Text
olecon = New OleDb.OleDbConnection
olecon.ConnectionString = connstring
olecomm = New OleDb.OleDbCommand
olecomm.CommandText = "Insert into [Sheet1$]" & _
"(purchaseitemcode, crosssellitemcode, startdate, enddate, discount, displayonprod, displayoncart, show) values ('" + purchase.Text + "', '" + ListBox3.Text + "' ,'" + DateTimePicker1.Text + "' , '" + DateTimePicker2.Text + "', '" + TextBox3.Text + "', '" + ListBox1.Text + "', '" + ListBox2.Text + "', '" + TextBox4.Text + "')"
olecomm.Connection = olecon
pram = olecomm.Parameters.Add("'" + purchase.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "purchaseitemcode"
pram = olecomm.Parameters.Add("'" + ListBox3.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "crosssellitemcode"
pram = olecomm.Parameters.Add("'" + DateTimePicker1.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "startdate"
pram = olecomm.Parameters.Add(" '" + DateTimePicker2.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "enddate"
pram = olecomm.Parameters.Add("'" + TextBox3.Text + "'", OleDb.OleDbType.Integer)
pram.SourceColumn = "discount"
pram = olecomm.Parameters.Add("'" + ListBox1.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "displayonprod"
pram = olecomm.Parameters.Add("'" + ListBox2.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "displayoncart"
pram = olecomm.Parameters.Add("'" + TextBox4.Text + "'", OleDb.OleDbType.VarChar)
pram.SourceColumn = "show"
oleadpt = New OleDb.OleDbDataAdapter(olecomm)
ds = New DataSet
olecon.Open()
oleadpt.Fill(ds, "Sheet1")
olecon.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
olecon = Nothing
olecomm = Nothing
oleadpt = Nothing
ds = Nothing
pram = Nothing
End Try
End Sub
End Class
Here is my code I am getting same error. How can I resolve it?