Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Notify users

Notify users

Scheduled Pinned Locked Moved C#
helpdatabasequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hello guys, I'm reading from a database using this called below:

    private void GetAllMembers()//this will get members belonging to all clubs
    {
    string query = @"SELECT * FROM [member_details] INNER JOIN club_details ON club_details.memberno = member_details.memberno WHERE [date_added] BETWEEN '" + date_from.SelectedValue.ToString() + "' AND '" + date_to.SelectedValue.ToString() + "'AND primsecconttype = '" + memb_type.SelectedValue.ToString() + "' AND [contracttype] = '" + class_type.SelectedValue.ToString() + "'";
    try
    {
    conn.Close();
    cmd = conn.CreateCommand();
    cmd.CommandText = query;
    conn.Open();
    reader = cmd.ExecuteReader();
    memb_names.Items.Clear();
    while (reader.Read())
    {
    string firstnames = (string)reader["firstname"];
    memb_names.Items.Add(firstnames);
    //ProcessReportViewed();//this will call a method called UpdateReportViewed in the Manager.cs class, it will pass a user_id for this user, go there and see what goes on...
    }
    if (!reader.Read())
    {
    error.Visible = true;
    error.Text = "Sorry no mambers found in this range..";
    }
    //else
    //{

                //}
                
                
            }
            catch (SqlException fff)
            {
                error.Visible = true;
                error.Text = "Error occured: " + fff.Message;
            }
        }
    

    The issue is that, when I read from a database and no record is returned I would like to let the user know. it works when I use an if() else statement but this will only return one record if by chance the query returns something. A while loop returns all the records, but I AM FAILING to find a way I can let the user know if the query returns nothing after using a while loop. Any help please on how I can let the user know if a while loop returns nothing???:confused: Thanks, Mo

    G 1 Reply Last reply
    0
    • M Morgs Morgan

      Hello guys, I'm reading from a database using this called below:

      private void GetAllMembers()//this will get members belonging to all clubs
      {
      string query = @"SELECT * FROM [member_details] INNER JOIN club_details ON club_details.memberno = member_details.memberno WHERE [date_added] BETWEEN '" + date_from.SelectedValue.ToString() + "' AND '" + date_to.SelectedValue.ToString() + "'AND primsecconttype = '" + memb_type.SelectedValue.ToString() + "' AND [contracttype] = '" + class_type.SelectedValue.ToString() + "'";
      try
      {
      conn.Close();
      cmd = conn.CreateCommand();
      cmd.CommandText = query;
      conn.Open();
      reader = cmd.ExecuteReader();
      memb_names.Items.Clear();
      while (reader.Read())
      {
      string firstnames = (string)reader["firstname"];
      memb_names.Items.Add(firstnames);
      //ProcessReportViewed();//this will call a method called UpdateReportViewed in the Manager.cs class, it will pass a user_id for this user, go there and see what goes on...
      }
      if (!reader.Read())
      {
      error.Visible = true;
      error.Text = "Sorry no mambers found in this range..";
      }
      //else
      //{

                  //}
                  
                  
              }
              catch (SqlException fff)
              {
                  error.Visible = true;
                  error.Text = "Error occured: " + fff.Message;
              }
          }
      

      The issue is that, when I read from a database and no record is returned I would like to let the user know. it works when I use an if() else statement but this will only return one record if by chance the query returns something. A while loop returns all the records, but I AM FAILING to find a way I can let the user know if the query returns nothing after using a while loop. Any help please on how I can let the user know if a while loop returns nothing???:confused: Thanks, Mo

      G Offline
      G Offline
      Greg Chelstowski
      wrote on last edited by
      #2

      OK. First of all, look up parameterized queries, if you can't use stored procedures. Second, I fail to realize what your problem is. Your while loop adds items to your collection, why not check the length of the collection after the while loop has run? If it's 0 - obviously no records were returned. And third: close your connection. Maybe add a finally statement to your try-catch? :)

      var question = (_2b || !(_2b));

      M 1 Reply Last reply
      0
      • G Greg Chelstowski

        OK. First of all, look up parameterized queries, if you can't use stored procedures. Second, I fail to realize what your problem is. Your while loop adds items to your collection, why not check the length of the collection after the while loop has run? If it's 0 - obviously no records were returned. And third: close your connection. Maybe add a finally statement to your try-catch? :)

        var question = (_2b || !(_2b));

        M Offline
        M Offline
        Morgs Morgan
        wrote on last edited by
        #3

        Thanks man, you have made sound so simple. I will try that

        G 1 Reply Last reply
        0
        • M Morgs Morgan

          Thanks man, you have made sound so simple. I will try that

          G Offline
          G Offline
          Greg Chelstowski
          wrote on last edited by
          #4

          MorgSim wrote:

          Thanks man, you have made sound so simple. I will try that

          "It's all relative". ;) Seriously, good luck. I'm sure you'll get there.

          var question = (_2b || !(_2b));

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups