RE: Trying to use ExecuteNonQuery on Command crashes
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Sun, 15 May 2005 16:22:21 +0000 (UTC)
Dessi Bravo (DessiBravo@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
> 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
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, esquel@xxxxxxxxxxxxx
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
.
- 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: RE: Trying to use ExecuteNonQuery on Command crashes
- Next by Date: Could not lock file
- Previous by thread: RE: Trying to use ExecuteNonQuery on Command crashes
- Next by thread: COMException (0x80040154): Class not registered
- Index(es):
Relevant Pages
|