Click here to Skip to main content
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 12:46pm
Edited 27-Jan-13 13:46pm
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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 963
1 Tadit Dash 270
2 Sergey Alexandrovich Kryukov 250
3 OriginalGriff 233
4 Peter Leow 180
0 Sergey Alexandrovich Kryukov 9,435
1 OriginalGriff 5,498
2 Peter Leow 4,230
3 Maciej Los 3,540
4 Abhinav S 3,353


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