hi
I created a button to save the details in ms_access database with oledb but when I run my project and click save button I get an error message saying that "error in insert into statement" any help please.
here is my code
Private Sub Button1_Click(s ender As Object, e As EventArgs) Handles Button1.Click
provider = "Provider=Micro soft.ACE.OLEDB. 12.0;Data Source="
datafile = "C:\Users\user\ Documents\Datab ase51111.accdb"
connString = provider & datafile
myConnection.Co nnectionString = connString
myConnection.Op en()
Dim str As String
'str = "insert into files([number],[fname],[from],[to],[date],[recom])Values(?,?,?,? ,?)"
str = "INSERT INTO allocate ([IDE],[IT],[SE],[ITE],[DATEE],[FROM],[TO],[DE],[ASSTE],[QUA],[RETE],[RE],[DAM],[STAT]) Values (?,?,?,?,?,?,?, ?,?,?,?,?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(st r, myConnection)
cmd.Parameters. Add(New OleDbParameter( "IDE", CType(TextBox1. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "IT", CType(TextBox2. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "SE", CType(TextBox3. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "ITE", CType(TextBox4. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DATEE", CType(DateTimeP icker1.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "FROM", CType(TextBox6. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "TO", CType(TextBox7. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DE", CType(TextBox8. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "ASSTE", CType(DateTimeP icker2.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "QUA", CType(TextBox10 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "RETE", CType(DateTimeP icker3.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "RE", CType(TextBox12 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DAM", CType(TextBox13 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "STAT", CType(TextBox14 .Text, String)))
Try
cmd.ExecuteNonQ uery()
cmd.Dispose()
myConnection.Cl ose()
Me.TextBox1.Tex t = ""
Me.TextBox2.Tex t = ""
Me.TextBox3.Tex t = ""
Me.TextBox4.Tex t = ""
Me.TextBox6.Tex t = ""
Me.TextBox7.Tex t = ""
Me.TextBox8.Tex t = ""
Me.TextBox10.Te xt = ""
Me.TextBox12.Te xt = ""
Me.TextBox13.Te xt = ""
Me.TextBox14.Te xt = ""
'Exit Sub
'End With
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
End Try
Me.Hide()
frmmain.Show()
End Sub
I created a button to save the details in ms_access database with oledb but when I run my project and click save button I get an error message saying that "error in insert into statement" any help please.
here is my code
Private Sub Button1_Click(s ender As Object, e As EventArgs) Handles Button1.Click
provider = "Provider=Micro soft.ACE.OLEDB. 12.0;Data Source="
datafile = "C:\Users\user\ Documents\Datab ase51111.accdb"
connString = provider & datafile
myConnection.Co nnectionString = connString
myConnection.Op en()
Dim str As String
'str = "insert into files([number],[fname],[from],[to],[date],[recom])Values(?,?,?,? ,?)"
str = "INSERT INTO allocate ([IDE],[IT],[SE],[ITE],[DATEE],[FROM],[TO],[DE],[ASSTE],[QUA],[RETE],[RE],[DAM],[STAT]) Values (?,?,?,?,?,?,?, ?,?,?,?,?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(st r, myConnection)
cmd.Parameters. Add(New OleDbParameter( "IDE", CType(TextBox1. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "IT", CType(TextBox2. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "SE", CType(TextBox3. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "ITE", CType(TextBox4. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DATEE", CType(DateTimeP icker1.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "FROM", CType(TextBox6. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "TO", CType(TextBox7. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DE", CType(TextBox8. Text, String)))
cmd.Parameters. Add(New OleDbParameter( "ASSTE", CType(DateTimeP icker2.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "QUA", CType(TextBox10 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "RETE", CType(DateTimeP icker3.Value, String)))
cmd.Parameters. Add(New OleDbParameter( "RE", CType(TextBox12 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "DAM", CType(TextBox13 .Text, String)))
cmd.Parameters. Add(New OleDbParameter( "STAT", CType(TextBox14 .Text, String)))
Try
cmd.ExecuteNonQ uery()
cmd.Dispose()
myConnection.Cl ose()
Me.TextBox1.Tex t = ""
Me.TextBox2.Tex t = ""
Me.TextBox3.Tex t = ""
Me.TextBox4.Tex t = ""
Me.TextBox6.Tex t = ""
Me.TextBox7.Tex t = ""
Me.TextBox8.Tex t = ""
Me.TextBox10.Te xt = ""
Me.TextBox12.Te xt = ""
Me.TextBox13.Te xt = ""
Me.TextBox14.Te xt = ""
'Exit Sub
'End With
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
End Try
Me.Hide()
frmmain.Show()
End Sub
Comment