PC Review


Reply
Thread Tools Rate Thread

Re: How to pass dataReader object

 
 
Val Mazur \(MVP\)
Guest
Posts: n/a
 
      14th Apr 2005
Hi,

You have an incorrect SQL statement. What are you trying to achieve with
this SQL statement? Following syntax is not correct, because @CustId
parameter does not belong to any condition

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



"Mori" <(E-Mail Removed)> wrote in message
news:0682863C-87EF-4B79-A9E4-(E-Mail Removed)...
>I am trying to pass a datareader object and then iterate through the reader
> in a client application. I get the following exception "Invalid attempt
> to
> read when no data is present."
>
> Question: What is the correct way to pass a dataReader? Any Good examples
> please. thanks
>
> public SqlDataReader GetCust(string CustId)
> {
> try
> {
> if (sqlConn.State == ConnectionState.Closed)
> sqlConn.Open();
> SqlCommand sqlCmd = new SqlCommand("SELECT * FROM dbo.ListCustomers
> (@CustId)", this.sqlConn);
> sqlCmd.CommandType = CommandType.Text;
> SqlParameter p0 = sqlCmd.Parameters.Add("@CustId", SqlDbType.VarChar, 3);
> p0.Value = CustId;
>
> SqlDataReader sqlRead =
> sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
> return sqlRead;
> }
> catch(Exception exep)
> {
> Console.WriteLine("An error occurred " + exep.Message.ToString());
> return null;
> }
> }
>
>
> //client
> static void Main(string[] args)
> {
> UserDefinedFunction.UDFSampler udf = new UDFSampler();
> SqlDataReader sRead = udf.GetCust("xyz");
> while (sRead.Read())
> {
> //do something with record
> }
> sRead.Close();
>
> }
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to process datareader nulls coming from datareader? JB Microsoft C# .NET 4 3rd Nov 2008 01:56 AM
Re: How to pass dataReader object William \(Bill\) Vaughn Microsoft ADO .NET 0 15th Apr 2005 06:56 PM
Re: How to pass dataReader object Sahil Malik [MVP] Microsoft ADO .NET 0 14th Apr 2005 07:48 PM
RE: How to pass dataReader object =?Utf-8?B?Sm9obiBQYXBh?= Microsoft ADO .NET 1 14th Apr 2005 12:29 PM
Re: pass javascript object reference to a session object Girish bharadwaj Microsoft ASP .NET 0 15th Sep 2004 02:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:59 PM.