Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2009, 08:51 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default Help with C# DataReader

Error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'read'

Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
String strConString = ConfigurationManager.ConnectionStrings["SocialSystemConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection();
con.ConnectionString = strConString;

//create Command
SqlCommand cmd = new SqlCommand("Select TextInput FROM Update", con);

// Open Connection
con.Open();

//Create Dataset to store query
SqlDataReader reader = cmd.ExecuteReader();

//Read and display data
while (reader.read())
{
lblResult.Text += Reader("TextInput").ToString();
}

//Close Reader
reader.Close();
con.Close();

}
}

Wat is the problem..
 
Old March 8th, 2009, 08:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

maybe, reader.Read() ?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
julius (March 9th, 2009)
 
Old March 8th, 2009, 09:00 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

hey

hmm. i change to Read but it appears..

Compiler Error Message: CS0103: The name 'Reader' does not exist in the current context
 
Old March 8th, 2009, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

The error is very explicit. You know that C# is case sensitive, don't you?

copy this exact text: reader("TextInput").ToString()
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
julius (March 9th, 2009)
 
Old March 8th, 2009, 09:23 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

I am actually new to c#. Was doing vb all along. I got it.
But however,
it appears another error after i oversee the case.

Compiler Error Message: CS0118: 'reader' is a 'variable' but is used like a 'method'
 
Old March 8th, 2009, 09:56 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

it is solved. I changed the "(" to "["
Thanks anyway.

But another error occured.. sigh
Incorrect syntax near the keyword 'Update'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Update'.
 
Old March 8th, 2009, 11:25 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default Surround sql keywords in square brackets

Hi Julius
Update is an sql server keyword. To stop this exact error, it is recommended not to use keywords for the names of tables etc. It is however possible to use them by putting [] round it (this is why if you script tables in SQL Management Studio it always surrounds the names of objects in []).
So your sql statement will look like
Code:
Select TextInput FROM [Update]
Hope this helps
Phil
The Following User Says Thank You to philip_cole For This Useful Post:
julius (March 9th, 2009)
 
Old March 8th, 2009, 11:47 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

Yeah. Thanks alot. :D

But however, i encounter anyproblem.. when i Inner join 2 tables together.

It shows the error below:
Incorrect syntax near 'User'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'User'.


protectedvoid Button1_Click(object sender, EventArgs e)
{
String strConString = ConfigurationManager.ConnectionStrings["SocialSystemConnectionString"].ConnectionString;
SqlConnection con = newSqlConnection();
con.ConnectionString = strConString;
//create Command
SqlCommand cmd = newSqlCommand("SELECT [Update].Email, [Update].TextInput, [User].FullName FROM [Update] INNERJOIN [User] ON [Update].Email = [User].Email", con);
// Open Connection
con.Open();
//Execute Command
SqlDataReader reader = cmd.ExecuteReader();
//Read and display data
while (reader.Read())
{
lblResult.Text += reader[
"FullName"].ToString() + " receive a new comment" + "<br/>" + reader["TextInput"].ToString() + "<br/>";
}
//Close Reader
reader.Close();
con.Close();
lblResult.Visible =
true;
}

Why is this so?
 
Old March 8th, 2009, 12:15 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

It looks like you have put innerjoin as one word, it should be 2: INNER JOIN
The Following User Says Thank You to philip_cole For This Useful Post:
julius (March 9th, 2009)
 
Old March 8th, 2009, 10:26 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

thanks pal !





Similar Threads
Thread Thread Starter Forum Replies Last Post
datareader MunishBhatia ASP.NET 2.0 Professional 2 October 17th, 2007 07:05 AM
regarding datareader adityamadisetty VB.NET 1 May 8th, 2006 09:31 AM
DataReader truongnnhat ASP.NET 1.0 and 1.1 Basics 2 February 18th, 2005 12:41 AM
datareader surapongmax ADO.NET 1 October 8th, 2004 07:53 AM
DataReader cjcd BOOK: Beginning ASP.NET 1.0 2 March 21st, 2004 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.