Click here to Skip to main content
11,495,524 members (66,768 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
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 27-Jan-13 13:46pm
Edited 27-Jan-13 14:46pm
(no name)18.1K
v2
Comments
Mike Meinz at 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.
du[DE] at 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)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 CHill60 318
2 Sascha Lefèvre 265
3 Nakul Chaudhari 236
4 Sergey Alexandrovich Kryukov 230
0 Sergey Alexandrovich Kryukov 10,322
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,889
3 Maciej Los 3,422
4 Richard Deeming 2,560


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100