Discussion:
Trying to use ExecuteNonQuery on Command crashes
(too old to reply)
Imry
2005-05-04 20:20:01 UTC
Permalink
Hi.
I'm using the ExecuteNonQuery command, and everytime I try running it, I get
this error: "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll".
When I run the SQL in ACCESS itself, it work perfectly.
I would appriciate any help.

This is my code:

Dim NewConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db1.mdb"

Dim NewConnection As New OleDbConnection(NewConnectionString)

Dim NewSQL As String = "UPDATE Important_Dates SET session = 3 where college
= 'CAS'"

Dim NewCommand As New OleDbCommand(NewSQL, NewConnection)

NewCommand.Connection.Open()

NewCommand.ExecuteNonQuery()
cpuckle
2005-05-05 03:05:01 UTC
Permalink
Hi, Imry,

I'm not exactly sure how different VB.net is from C#, but you might want to
try the following. You probably need to fix my syntax :)

Dim NewConnection as new OleDbConnection(NewConnectionString)
Dim NewCommand as NewConnection.CreateCommand()
Post by Imry
Hi.
I'm using the ExecuteNonQuery command, and everytime I try running it, I get
this error: "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll".
When I run the SQL in ACCESS itself, it work perfectly.
I would appriciate any help.
Dim NewConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db1.mdb"
Dim NewConnection As New OleDbConnection(NewConnectionString)
Dim NewSQL As String = "UPDATE Important_Dates SET session = 3 where college
= 'CAS'"
Dim NewCommand As New OleDbCommand(NewSQL, NewConnection)
NewCommand.Connection.Open()
NewCommand.ExecuteNonQuery()
Sameer
2005-05-06 05:57:37 UTC
Permalink
It can also be a problem with the column size or type,
youmight be tryingto insert a string in int col or string with size 10 where
it accepts less than that.
Post by Imry
Hi.
I'm using the ExecuteNonQuery command, and everytime I try running it, I get
this error: "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll".
When I run the SQL in ACCESS itself, it work perfectly.
I would appriciate any help.
Dim NewConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db1.mdb"
Dim NewConnection As New OleDbConnection(NewConnectionString)
Dim NewSQL As String = "UPDATE Important_Dates SET session = 3 where college
= 'CAS'"
Dim NewCommand As New OleDbCommand(NewSQL, NewConnection)
NewCommand.Connection.Open()
NewCommand.ExecuteNonQuery()
Dessi Bravo
2005-05-13 21:50:01 UTC
Permalink
I you could help me in this code. I am trying to authenticate the code in a
login page that i created but continue to get an error in the ExecuteReader.
It says that it requires a connection and available connection. the current
state is closed.
Here is the code that i created:
I appreciate your assistance.
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & mypath & ";Jet OLEDB:Database Password=" & Password)
Dim cmd As OleDbCommand

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username =
'" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"

cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
If conn.State <> ConnectionState.Open Then
conn.Open()
End If

Try
conn.Open()

Catch ex As InvalidOperationException
MsgBox(ex.Message)

End Try
Try
If dr.Read = False Then
MessageBox.Show("Authentication Failed...")
Else
MessageBox.Show("Login Successful...")

End If
Catch ex As Exception
MsgBox(ex.Message)

End Try

If conn.State <> ConnectionState.Closed Then
conn.Close()

End If


Dim form As New Form2
form.Show()
Post by Sameer
It can also be a problem with the column size or type,
youmight be tryingto insert a string in int col or string with size 10 where
it accepts less than that.
Post by Imry
Hi.
I'm using the ExecuteNonQuery command, and everytime I try running it, I get
this error: "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll".
When I run the SQL in ACCESS itself, it work perfectly.
I would appriciate any help.
Dim NewConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db1.mdb"
Dim NewConnection As New OleDbConnection(NewConnectionString)
Dim NewSQL As String = "UPDATE Important_Dates SET session = 3 where college
= 'CAS'"
Dim NewCommand As New OleDbCommand(NewSQL, NewConnection)
NewCommand.Connection.Open()
NewCommand.ExecuteNonQuery()
Dessi Bravo
2005-05-15 05:53:01 UTC
Permalink
Is there anyone that could help me with my question on the ExecuteReader?
Post by Dessi Bravo
I you could help me in this code. I am trying to authenticate the code in a
login page that i created but continue to get an error in the ExecuteReader.
It says that it requires a connection and available connection. the current
state is closed.
I appreciate your assistance.
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & mypath & ";Jet OLEDB:Database Password=" & Password)
Dim cmd As OleDbCommand
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username =
'" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
Try
conn.Open()
Catch ex As InvalidOperationException
MsgBox(ex.Message)
End Try
Try
If dr.Read = False Then
MessageBox.Show("Authentication Failed...")
Else
MessageBox.Show("Login Successful...")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If conn.State <> ConnectionState.Closed Then
conn.Close()
End If
Dim form As New Form2
form.Show()
Post by Sameer
It can also be a problem with the column size or type,
youmight be tryingto insert a string in int col or string with size 10 where
it accepts less than that.
Post by Imry
Hi.
I'm using the ExecuteNonQuery command, and everytime I try running it, I get
this error: "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll".
When I run the SQL in ACCESS itself, it work perfectly.
I would appriciate any help.
Dim NewConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\db1.mdb"
Dim NewConnection As New OleDbConnection(NewConnectionString)
Dim NewSQL As String = "UPDATE Important_Dates SET session = 3 where college
= 'CAS'"
Dim NewCommand As New OleDbCommand(NewSQL, NewConnection)
NewCommand.Connection.Open()
NewCommand.ExecuteNonQuery()
Erland Sommarskog
2005-05-15 16:22:21 UTC
Permalink
Post by Dessi Bravo
I you could help me in this code. I am trying to authenticate the code
in a login page that i created but continue to get an error in the
ExecuteReader. It says that it requires a connection and available
connection. the current state is closed.
I appreciate your assistance.
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & mypath & ";Jet OLEDB:Database Password=" & Password)
Dim cmd As OleDbCommand
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username =
'" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
You should connect before you call ExecuteReader.

As for the lack or response, this group is not really about ADO .Net,
but using the OLE DB API. Next time you should probably try
microsoft.public.dotnet.framework.adonet.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Loading...