Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi, I have a problem with my coding. The error which i got is oleDbException was unhandled. Here I am developing function use to subtract number in database based on user input. I don't know how to solve this error , Please help me to correct my coding here. I also highlight the line causing an error

Imports System.Data.OleDb
Public Class Add_LEads
Dim con As New OleDbConnection
Dim cmd As New OleDbCommand
Dim da As New OleDbDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|C:\Users\Mylene\Desktop\FDQOH")
lblDate.Text = Format(Date.Now, "yyyy/MM/dd")
Try
con.Open()
Catch ex As InvalidOperationException
MessageBox.Show(ex.Message)
End Try
Dim sql As String
Dim a As Integer
sql = "select S_No from Leadss"
cmd = New OleDbCommand(sql, con)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
While dr.Read
a = dr(0)
End While
lblNo.Text = a + 1
con.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO Leadss(SR-CODE,LName,FName,MInitial,Sec)VALUES('" & sr.Text & "','" & lname.Text & "','" & fname.Text & "','" & midint.Text & "','" & sec.Text & "')"
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Saved!!!", vbOK)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
MessageBox.Show("WELCOME")
End Sub
End Class
Posted
Updated 27-Jan-13 13:46pm
v2
Comments
Mike Meinz 27-Jan-13 19:12pm    
On which statement do you get the error? Have you stepped through your code using the Visual Studio Debugger? Do any of the values contain a quote character (')? If so, that is your error.

You should use SQLParameter class to pass parameters to the database to solve this issue and to prevent SQL Injection Attacks.

You classified this question as C++ LINUX. It is not that. It is VB.NET. Please correct the classification of your question.
Leo Chapiro 28-Jan-13 1:58am    
Why have you tagged this question with Linux?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900