RE: Trying to use ExecuteNonQuery on Command crashes



Is there anyone that could help me with my question on the ExecuteReader?

"Dessi Bravo" wrote:

> 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()
>
>
>
>
>
>
> "Sameer" wrote:
>
> > 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.
> >
> > "Imry" wrote:
> >
> > > 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()
.



Relevant Pages

  • ExecuteReader: Connection property not initialized
    ... ExecuteReader: Connection property has not been initialized. ... Dim comd As SqlCommand ... Dim sConnectionString As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Oracle Data Provider Insert Time (Need Help)
    ... Why do you use ExecuteReader and not ExecuteNonQuery? ... > Below is code using the Oracle Data Adaptor and VB.NET. ... > Dim con As New OracleConnection ... > Dim SQL As String ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Reading Single Value from a SQL DB [FIXED]
    ... Its a cheaper operation than ExecuteReader, when you know you only want 1 ... Dim objConnection As New SqlConnection ... Dim strResult As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Stored Procedure Results
    ... Adapter.Fill - then you don't need ExecuteReader and vice versa. ... > SELECT FO, Pull, Config, StartSNRange FROM tblSerialNum WHERE FO = @FO ... > Dim dsResults As String ... > Dim dsStartResults As String ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Trying to use ExecuteNonQuery on Command crashes
    ... It says that it requires a connection and available connection. ... Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data ... > youmight be tryingto insert a string in int col or string with size 10 where ... >> Dim NewConnection As New OleDbConnection ...
    (microsoft.public.data.oledb)