fizzled
Well-known member
My current code is intended to retrieve the number of entries in a database table, then retrieve these entries if the count is greater than 0. I assume I can simply reuse the same OleDbDataReader object for both queries, but Im getting a "Type mismatch in expression" error. Im not sure if this is because Im reusing the OleDbDataReader object, an OleDbCommand object, or if there is a problem with my boolean parameter. The code is as follows:
The error occurs on the red line.
PS - My host (Brinkster.com) sets the following ASP Rule:
"Set all objects you use equal to Nothing when you are done with them. (ie. "Set Conn = Nothing")"
So I tacked on the "rdrBlog = null; cmdBlog = null; cnBlog = null;" there at the end of my code. I assume in C# this produces the same result?
Code:
public void Page_Load (object Sender, EventArgs e) {
string qryActiveCount = "SELECT COUNT(BlogID) AS ActiveCount FROM Blogs WHERE BlogActive = @BlogActive";
string qryActiveBlogs = "SELECT B.BlogID, B.BlogTitle, B.BlogPostDate, B.BlogText, U.PublicName AS AuthorName FROM Blogs AS B INNER JOIN BlogUsers AS U ON B.BlogAuthor = U.UserID WHERE B.BlogActive = @BlogActive";
OleDbConnection cnBlog = new OleDbConnection(Application.Contents["FBConnStr"].ToString());
OleDbCommand cmdBlog = new OleDbCommand(qryActiveCount, cnBlog);
OleDbDataReader rdrBlog;
cmdBlog.Parameters.Clear();
cmdBlog.Parameters.Add(new OleDbParameter("@BlogActive", OleDbType.Boolean));
cmdBlog.Parameters["@BlogActive"].Value = true;
cnBlog.Open();
rdrBlog = cmdBlog.ExecuteReader();
if (rdrBlog.HasRows) {
rdrBlog.Read();
if (Convert.ToInt32(rdrBlog["ActiveCount"]) > 0) {
rptrActiveBlogs.Visible = true;
}
}
rdrBlog.Close();
if (rptrActiveBlogs.Visible) {
cmdBlog.CommandText = qryActiveBlogs;
cmdBlog.Parameters.Clear();
cmdBlog.Parameters.Add(new OleDbParameter("@BlogActive", OleDbType.Boolean));
cmdBlog.Parameters["@BlogActive"].Value = true;
[color=red]rdrBlog = cmdBlog.ExecuteReader();[/color]
rptrActiveBlogs.DataSource = rdrBlog;
rptrActiveBlogs.DataBind();
rdrBlog.Close();
} else {
litBlogEmpty.Visible = true;
}
cnBlog.Close();
rdrBlog = null;
cmdBlog = null;
cnBlog = null;
}
The error occurs on the red line.
PS - My host (Brinkster.com) sets the following ASP Rule:
"Set all objects you use equal to Nothing when you are done with them. (ie. "Set Conn = Nothing")"
So I tacked on the "rdrBlog = null; cmdBlog = null; cnBlog = null;" there at the end of my code. I assume in C# this produces the same result?