Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
3.20/5 (2 votes)
See more:
I am getting an error:

VB
Invalid attempt to read when no data is present.


User1 and Pass1 produce two different strings of data
User1:
ASP.NET
<asp:TextBox ID="TextBox1" runat="server">


Pass1:
ASP.NET
<input id="Password1" type="password"  runat="server" />


Here is my code:

VB
User1 = TextBox1.Text
Pass1 = Password1.Value.ToString()
    cmdStr = "SELECT ids FROM sessionregister WHERE username=@username AND password=@password;"
    Using conn As New SqlConnection(connStr)
        Using cmd As New SqlCommand(cmdStr, conn)
            conn.Open()
            cmd.Parameters.AddWithValue("@username", User1)
            cmd.Parameters.AddWithValue("@password", Pass1)
            cmd.ExecuteNonQuery()
Posted

1 solution

ExecuteNonQuery does not return data, so will not work for a SELECT. You want maybe ExecuteReader.
Or

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
object value=cmd.ExecuteScalar()
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900