Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

asp.net csharp OleDbDataReader prob

Options
  • 17-02-2006 8:03pm
    #1
    Registered Users Posts: 742 ✭✭✭


    Hi, im having a problem with the Oledb datareader

    the first code works perfectly for populating the combo box

    the second code gives me an error 'No data exists for the row/column.'
    i know it works to login when im not trying to get data from the reader, but i need to get their permission.

    any suggestions?

    oleDbConnection1.Open();
    string sql = "Select FlightID from FlightDeparture";
    System.Data.OleDb.OleDbCommand cmd = oleDbConnection1.CreateCommand();
    cmd.CommandText = sql;

    System.Data.OleDb.OleDbDataReader reader = cmd.ExecuteReader();

    while(reader.Read())
    {
    string ID = reader.GetString(0);
    cboFlightID.Items.Add(ID);
    }

    reader.Close();
    oleDbConnection1.Close();

    _________________________________________________
    _________________________________________________
    _________________________________________________

    oleDbConnection1.Open();
    string sql = "Select Usernames, Passwords, Permissions from Authentication where Usernames = '" + txtUsername.Text + "' and Passwords='" + txtPassword.Text + "'";
    System.Data.OleDb.OleDbCommand cmd = oleDbConnection1.CreateCommand();
    cmd.CommandText = sql;

    System.Data.OleDb.OleDbDataReader reader = cmd.ExecuteReader();

    while(reader.Read())
    {
    string Username = reader.GetString(0);
    string Permission = reader.GetString(3);
    }
    txtPermission.Text = Permission
    reader.Close();
    oleDbConnection1.Close();


Comments

  • Closed Accounts Posts: 35 Ivan Dunaev


    string sql = "Select Usernames, Passwords, Permissions from Authentication where Usernames = '" + txtUsername.Text + "' and Passwords='" + txtPassword.Text + "'";
    ...
    string Permission = reader.GetString(3);
    why 3?


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    It's good practice to refer to the columns in the reader by textual name instead numeric index, the name is less likely to change over time and it's easier to read and make changes when needed.


  • Closed Accounts Posts: 5 clancy


    Have you tried testing your SQL statement in your DB using its SQL query editor.

    You'll have to take this string though and make changes:

    "Select Usernames, Passwords, Permissions from Authentication where Usernames = '" + txtUsername.Text + "' and Passwords='" + txtPassword.Text + "'";

    "Select Usernames, Passwords, Permissions from Authentication where Usernames = 'Loco' and Passwords='somePassword'";

    If this doesnt work you should try replacing the "Usernames, Passwords, Permissions" part with just a "*" until you get it working.


  • Registered Users Posts: 4,073 ✭✭✭muckwarrior


    why 3?
    Yep thats the problem. It should be 2. You're trying to read a column that doesn't exist.


  • Registered Users Posts: 742 ✭✭✭Loco


    another stupid mistake i fixed

    nah permissions column lies at index 3 alrite, email is index 2

    i misplaced the .getstring methods outside the while loop

    my bad


  • Advertisement
Advertisement