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();
>
> }
>
>