RE: Trying to use ExecuteNonQuery on Command crashes
- From: "Dessi Bravo" <DessiBravo@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 14 May 2005 22:53:01 -0700
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()
.
- References:
- Trying to use ExecuteNonQuery on Command crashes
- From: Imry
- RE: Trying to use ExecuteNonQuery on Command crashes
- From: Sameer
- RE: Trying to use ExecuteNonQuery on Command crashes
- From: Dessi Bravo
- Trying to use ExecuteNonQuery on Command crashes
- Prev by Date: How to update a table only with the missing row (identified by pri
- Next by Date: RE: Trying to use ExecuteNonQuery on Command crashes
- Previous by thread: RE: Trying to use ExecuteNonQuery on Command crashes
- Next by thread: RE: Trying to use ExecuteNonQuery on Command crashes
- Index(es):
Relevant Pages
|