Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-15-2004, 05:50 AM   #1 (permalink)
watherton
Registered User
 
Join Date: Jun 2004
Posts: 2
watherton is on a distinguished road
DataReader empty

ok i have this slight problem that is beginning to wear me down.

I have a method that calls a class, which is supposed to return the method a datareader object. When the class returns to the method though the datareader is empty.

here is the code:

public SqlDataReader AuthenticateUser()
{


SqlDataReader dataReader = null;
Classes.Connection conn = new Connection();

SqlParameter[] prams =
{
conn.MakeInParam("@Username",SqlDbType.Char,10,str Username),
conn.MakeInParam("@Password",SqlDbType.Char,10,str Password),
conn.MakeOutParam("@UserID",SqlDbType.Int,4),
conn.MakeOutParam("@bSuccess",SqlDbType.Bit,1),
conn.MakeOutParam("@dLastLogon",SqlDbType.DateTime ,8)
};

conn.RunProc("sp_CheckLogon",prams, out dataReader)

return datareader

here is the calling method

public void RunProc(string procName, SqlParameter[] prams, out SqlDataReader dataReader)
{
SqlCommand objCMD = CreateCommand(procName, prams);
dataReader = objCMD.ExecuteReader();
}


the orignal code was taken from this website ('http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=3) if that helps.

what i need to happen is access the elements with the datareader and populate my local variables etc, but everytime i create a reader.read() object it just ends up in a continous loop because the datareader is empty.

If i have not made myself clear then please say so - any help would be a massive help.

Cheers

Wayne
watherton is offline   Reply With Quote
Old 06-15-2004, 09:58 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
what type of database are you trying to read?

can you also show the code you are trying to read with? your reader is named 'dataReader' , so your loop should be dataReader.Read();
Code:
public void RunProc(string procName, SqlParameter[] prams, out SqlDataReader dataReader)
{
  SqlCommand objCMD = CreateCommand(procName, prams);
  dataReader = objCMD.ExecuteReader();

  // your loop should be something like this i think
  while(dataReader.Read())
  {

  }
}
__________________
Mike
sde is offline   Reply With Quote
Old 06-15-2004, 10:02 AM   #3 (permalink)
watherton
Registered User
 
Join Date: Jun 2004
Posts: 2
watherton is on a distinguished road
datareader

Sql 2000
watherton is offline   Reply With Quote
Old 06-15-2004, 11:58 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i think it would be easier for you to use this approach:
Code:
using System;
using System.Data.SqlClient;

public class Test
{
  public static void Main()
  {
    Test t=new Test();
    t.Run();
  }
  
  public void Run()
  {
    SqlConnection conn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs");
    SqlCommand  cmd = new SqlCommand("SELECT * FROM emp_test", conn);
    try
    {    	
      conn.Open();
      
      SqlDataReader myReader = cmd.ExecuteReader();
      Console.WriteLine("Code \t Emp. Name \t Emp. Phone");
      Console.WriteLine("-----------------------------------------");
      while (myReader.Read())
      {
        Console.WriteLine("{0}\t{1}\t\t{2}", myReader.GetInt32(0), myReader.GetString(1), myReader.GetString(2));
      }
    		
      myReader.Close();
      conn.Close();
    }
    catch(Exception e)
    {
      Console.WriteLine("Exception Occured -->> {0}",e);
    }    	
  }
}
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP N00b - How to check if a variable is set? or empty? helz MS Technologies ( ASP, VB, C#, .NET ) 3 11-04-2004 10:19 AM


All times are GMT -8. The time now is 11:21 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting