Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:57:18+00:00 2026-06-12T21:57:18+00:00

I’m trying to develop a little user-user messaging system in C# (my first C#

  • 0

I’m trying to develop a little user-user messaging system in C# (my first C# app) using a mysql database.

I know best practice would be to use something like EF for working with the database, but I’m writing this the “stupid” way just to get comfortable with the syntax.

I come from a vb background so I’m basically just converting what I normally do in vb and that’s why I can’t understand why, despite having a matching row in my database, the DataReader keeps coming back with no rows. See below:

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Page.Validate("Login");

        if (!IsValid)
        {
            return;
        }

        if (checkLogin())
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            lblErr.Text = "Invalid login attempt";
        }
    }

    protected Boolean checkLogin()
    {
        MySql db = new MySql();

        string sql = "select userid, firstname, lastname, ifnull(lastlogin, '') from users where email = @email and pass = @pass";

        List<MySqlParameter> args = new List<MySqlParameter>();
        args.Add(new MySqlParameter() { ParameterName = "@email", MySqlDbType = MySqlDbType.VarChar, Size = 100, Value = txtEmail.Text });
        args.Add(new MySqlParameter() { ParameterName = "@pass", MySqlDbType = MySqlDbType.VarChar, Size = 20, Value = txtPass.Text });

        MySqlDataReader dr = db.getReader(sql, args);

        if (dr.HasRows)
        {
            dr.Read();

            Session["userid"] = dr.GetInt32("userid");
            Session["firstname"] = dr.GetString("firstname");
            Session["lastname"] = dr.GetString("lastname");
            Session["lastlogin"] = dr.GetDateTime("lastlogin");

            dr.Close();

            return true;
        }
        else
        {
            return false;
        }
    }

The above code checks the user input against the database and returns a row if there are any rows in the table that match the user input…

Here’s the code for the interaction with the database…

public class MySql
{
    static string connStr = "data source=localhost; initial catalog=mail; user id=root; password=Ly@12157114;";
    MySqlConnection conn = new MySqlConnection(connStr);

    public MySqlDataReader getReader(string sql, List<MySqlParameter> args)
    {
        if (args.Count == 0)
        {
            return getReader(sql);
        }
        else
        {
            return getReader(sql, args.ToArray());
        }
    }
    public MySqlDataReader getReader(string sql, MySqlParameter[] args = null)
    {
        MySqlCommand cmd = new MySqlCommand(sql, conn);

        if (args != null)
        {
            cmd.Parameters.AddRange(args);
        }

        conn.Open();

        MySqlDataReader dr = cmd.ExecuteReader();

        conn.Close();

        return dr;
    }
}

I get no errors or any indication that something has gone wrong here and I’m positive there is data that match my input into the login fields.

Can anyone help me to understand why the DataReader keeps coming back empty?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:57:19+00:00Added an answer on June 12, 2026 at 9:57 pm

    The connection of your data reader must be opened when you use it. The DataReader don’t retrieve any data when you create it, it retrieves data when you use it. It can not retrieve your all database before you close the connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.