Click here to Skip to main content
15,914,905 members
Home / Discussions / C#
   

C#

 
AnswerRe: Database Usage in Any language Pin
Wes Aday30-Aug-12 3:01
professionalWes Aday30-Aug-12 3:01 
Questionproblem while adding reference Pin
john563229-Aug-12 20:26
john563229-Aug-12 20:26 
AnswerRe: problem while adding reference Pin
Wayne Gaylard29-Aug-12 21:07
professionalWayne Gaylard29-Aug-12 21:07 
GeneralRe: problem while adding reference Pin
john563229-Aug-12 21:10
john563229-Aug-12 21:10 
GeneralRe: problem while adding reference Pin
Wayne Gaylard29-Aug-12 21:22
professionalWayne Gaylard29-Aug-12 21:22 
GeneralRe: problem while adding reference Pin
Ennis Ray Lynch, Jr.30-Aug-12 5:09
Ennis Ray Lynch, Jr.30-Aug-12 5:09 
GeneralRe: problem while adding reference Pin
Wayne Gaylard30-Aug-12 5:30
professionalWayne Gaylard30-Aug-12 5:30 
QuestionProblem Using ExecuteScalar Pin
ASPnoob29-Aug-12 18:56
ASPnoob29-Aug-12 18:56 
Hi all, I don't know whether this question should be posted here or in a the database forum because it involves both C# and database query statements, but here goes. I am trying to determine if a username password pair exists in the Engineer Table or in the writer table. First I check the Engineer Table for the username password pair using the SQL Count Function. If the pair does not exist then the Count Function returns 0, if it does exist then the Function returns a number greater than 0. I'm using Stored Proc1 to search in the Engineer Table and Stored Pro2 to search in the Writer Table. Below are my stored procedures.
Proc1
C#
SELECT Count(*)
FROM Engineer
WHERE  [User Name]= [@UserName] AND [Password] = [@Password] ;

Proc2
C#
SELECT Count(*)
FROM Writer
WHERE  [User Name]= [@UserName] AND [Password] = [@Password] ;

The following is my code
C#
public int StaffExists(string myPath, string UserName, string Password)
   {
       OleDbConnection OleConn = null;

       OleDbCommand oCommand = null;

       OleDbParameter param = null;

       OleConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + myPath + "");

       OleConn.Open();

                       //Passing in Proc1 Stored Proc
       oCommand = new OleDbCommand("Proc1", OleConn);

       oCommand.CommandType = CommandType.StoredProcedure;

       param = new OleDbParameter("@UserName", UserName);

       oCommand.Parameters.Add(param);

       param = new OleDbParameter("@Password", Password);

       oCommand.Parameters.Add(param);

       //First check in Engineer table
       oCommand.CommandText = "Proc1";

       int Count = (int)oCommand.ExecuteScalar();

       OleConn.Close();
       oCommand.Dispose();

       int UserCount = Count;
       int UserCount2 = 0;

       if (UserCount > 0)
       {  //User exists in Engineer table

           return UserCount;
       }
       else
       {
           if (UserCount == 0)
           { //User name not in Engineer table, check in Writer table

               OleConn.Open();
                                 // Pass in Proc2 Stored Proc
               oCommand = new OleDbCommand("Proc2", OleConn);

               oCommand.CommandType = CommandType.StoredProcedure;

               param = new OleDbParameter("@UserName", UserName);

               oCommand.Parameters.Add(param);

               param = new OleDbParameter("@Password", Password);

               oCommand.Parameters.Add(param);

               oCommand.CommandText = "Proc2";

               UserCount = (int)oCommand.ExecuteScalar();

               OleConn.Close();
               oCommand.Dispose();

               UserCount2 = UserCount;

               if (UserCount2 > 0)
               {//User exists in Writer table
               }
               else
               {
               }
           }

           return UserCount2;
       }
   }


The problem is no matter what username or password is entered they come back as invalid. Please help, thanks in advance.
AnswerRe: Problem Using ExecuteScalar Pin
Bernhard Hiller29-Aug-12 20:45
Bernhard Hiller29-Aug-12 20:45 
AnswerRe: Problem Using ExecuteScalar Pin
Rohit Kumar Gora30-Aug-12 4:08
Rohit Kumar Gora30-Aug-12 4:08 
QuestionUsing an Array inside a Class Pin
Jacob Rotary29-Aug-12 10:49
Jacob Rotary29-Aug-12 10:49 
AnswerRe: Using an Array inside a Class Pin
Matt T Heffron29-Aug-12 11:11
professionalMatt T Heffron29-Aug-12 11:11 
AnswerRe: Using an Array inside a Class Pin
Wes Aday29-Aug-12 11:14
professionalWes Aday29-Aug-12 11:14 
JokeRe: Using an Array inside a Class Pin
PIEBALDconsult29-Aug-12 11:30
mvePIEBALDconsult29-Aug-12 11:30 
GeneralRe: Using an Array inside a Class Pin
Wes Aday29-Aug-12 11:35
professionalWes Aday29-Aug-12 11:35 
AnswerRe: Using an Array inside a Class Pin
PIEBALDconsult29-Aug-12 11:33
mvePIEBALDconsult29-Aug-12 11:33 
AnswerRe: Using an Array inside a Class Pin
Kenneth Haugland29-Aug-12 11:51
mvaKenneth Haugland29-Aug-12 11:51 
AnswerRe: Using an Array inside a Class Pin
Bernhard Hiller29-Aug-12 20:49
Bernhard Hiller29-Aug-12 20:49 
AnswerRe: Using an Array inside a Class Pin
Pete O'Hanlon29-Aug-12 22:47
mvePete O'Hanlon29-Aug-12 22:47 
AnswerRe: Using an Array inside a Class Pin
harold aptroot30-Aug-12 2:39
harold aptroot30-Aug-12 2:39 
QuestionHow to get the properties of more than one display monitor attached to my computer Pin
Nathaniel Lim29-Aug-12 10:09
Nathaniel Lim29-Aug-12 10:09 
AnswerRe: How to get the properties of more than one display monitor attached to my computer Pin
Dave Kreskowiak29-Aug-12 13:04
mveDave Kreskowiak29-Aug-12 13:04 
QuestionRecruitment Pin
boys-esan29-Aug-12 10:09
boys-esan29-Aug-12 10:09 
QuestionGet Error when connect to DB2 on server Pin
kathytran29-Aug-12 7:07
kathytran29-Aug-12 7:07 
AnswerRe: Get Error when connect to DB2 on server Pin
Dave Kreskowiak29-Aug-12 12:58
mveDave Kreskowiak29-Aug-12 12:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.