|
-
Oct 14th, 2003, 10:16 AM
#1
Thread Starter
Frenzied Member
Reader Error
I am getting a couple of errors in my page_load event
First Error:
Cannot implicitly convert type 'int' to 'System.Data.SqlClient.SqlDataReader'
Second Error:
Operator '>=' cannot be applied to operands of type 'object' and 'int'
any ideas??? I am trying to return a count from the sql query, then check with the reader if that count is greater than 2.
Code:
private void Page_Load(object sender, System.EventArgs e)
{
string strConn = "Data Source=localhost;uid=steve;pwd=xxxxxx;Initial Catalog=mansion";
SqlConnection Conn = new SqlConnection(strConn);
SqlCommand Comm = new SqlCommand("SELECT rDate, COUNT(rDate) AS 'count' FROM reservations GROUP BY(rDate) HAVING COUNT(rDate) > 1", Conn);
SqlDataReader reader;
reader = Comm.ExecuteNonQuery();<------ First Error
while(reader.Read())
{
if(reader["count"] >= 2)<------------ Second Error
{
Calendar1.SelectedDates.Add(Convert.ToDateTime(reader["rDate"]));
}
}
reader.Close();
Conn.Close();
Conn = null;
}
Last edited by Memnoch1207; Oct 14th, 2003 at 10:22 AM.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 14th, 2003, 02:34 PM
#2
Thread Starter
Frenzied Member
I got it figured out.
First Error: ExecuteNonQuery() is used for Insert, update and delete, not when a query will return rows...So I changed it to ExecuteReader();
Second Error: The reader returns an object type field, so to get the integer value in "count" you have to convert it to an integer
Convert.ToInt32(reader["count"]);
and that fixed the problem!
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|