Notify users
-
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
-
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
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 yourtry-catch
? :)var question = (_2b || !(_2b));
-
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 yourtry-catch
? :)var question = (_2b || !(_2b));
Thanks man, you have made sound so simple. I will try that
-
Thanks man, you have made sound so simple. I will try that
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));