Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 December 6th, 2003, 05:29 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default I can't find bugs in my Login function. (User.cs)

I created "User.cs" in a "Components" File for "MyProject" project.
When I try to login using Login function in "User.cs", it always has
errors at myCommand.ExecuteNonQuery();. The error message is
"Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done." I thought the myCommand was wrong and checked the strSQL, but I couldn't find errors. If you could, could you please help me to fix the bugs?

The User.cs is following:
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;

namespace MyProject
{
public class UserDetails
{
public string VerifiedDate;
public string Prefix;
public string FirstName;
public string LastName;
public string Email;
public string UserPwd;
public string Address;
public string PhoneNumber;
public Int32 UserID;
}

public class User
{
public User()
{
}

public UserDetails Login(string strEmail, string
strPassword)
{
// Create Instance of Connection and Command
Object
String strConn
="Provider=Microsoft.Jet.OleDb.4.0;";
strConn += @"Data
Source=C:\MyProject\DB\HowardGroupWeb.mdb";
OleDbConnection myConnection = new
OleDbConnection(strConn) ;

string strSQL = "SELECT UserID, FirstName FROM
Users WHERE Email='"+strEmail+"' AND UserPwd='"+strPassword+"'";

OleDbCommand myCommand = new
OleDbCommand(strSQL,myConnection);

// Mark the Command as a SPROC
myCommand.CommandType =
CommandType.StoredProcedure;

// Add Parameters to SPROC
OleDbParameter prmEmail = new
OleDbParameter("@Email",OleDbType.VarChar,255);
prmEmail.Value = strEmail;
myCommand.Parameters.Add(prmEmail);

OleDbParameter prmFirstName = new
OleDbParameter("@FirstName",OleDbType.VarChar,255) ;
prmFirstName.Direction =
ParameterDirection.Output;
myCommand.Parameters.Add(prmFirstName);

OleDbParameter prmUPassword = new
OleDbParameter("@UserPwd",OleDbType.VarChar,255);
prmUPassword.Value = strPassword;
myCommand.Parameters.Add(prmUPassword);

OleDbParameter prmUserID = new
OleDbParameter("@UserID",OleDbType.BigInt);
prmUserID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(prmUserID);

UserDetails myUserDetails = new UserDetails();

try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();

myUserDetails.FirstName =
prmFirstName.Value.ToString();
myUserDetails.UserID =
Convert.ToInt32(prmUserID.Value);

return myUserDetails;
}
catch(OleDbException ODbexc)
{
myUserDetails.FirstName =
ODbexc.ToString();
myUserDetails.UserID = 0;
return myUserDetails;
}
}

Super thank you in advance,



 
Old December 6th, 2003, 06:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

From what I can see, you're having a couple of problems.

1. You're coding a normal SQL statement, yet you mark it as a sproc
2. You're adding parameters but you're not using any code to fill those params (e.g. I'd expect something like an output param)
3. You're using ExecuteNonQuery. This is usually used for UPDATE, DELETE statements, etc.

If I were you, I'd use a normal SQL Select statement (like you have now) and then use ExecuteReader to get a OledbDataReader.

If you look at the OledbDataReader help page, you'll get a good example on how to retrieve values from the DataReader.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 6th, 2003, 08:02 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, Imar. I fixed the bug as you suggested me.

I'm still confused about what the stored procedure is for. When I create a new row, I can use the SQL statement, "INSERT" or "UPDATE". The stored procedure is for only SQL Server?

Sorry for a lack of my knowledge.

 
Old December 6th, 2003, 08:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A stored procedure is made inside the database, and you simply call this using some parameter (variables) from the code. As far as I know this should be more efficient than regular SQL execution from code.

Not only for SQL server! I have tried in in Access.

Jacob.
 
Old December 7th, 2003, 03:38 AM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for explaining about the stored procedure. Make sense!

Kaz
 
Old December 7th, 2003, 05:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You may also want to take a look here:

http://searchdatabase.techtarget.com...334271,00.html

and

http://msdn.microsoft.com/library/de...es_07_31vb.asp

The last link will brink up a lot of other useful links (in the menu on the left) about using Stored Procedures in SQL Server.

Regards,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
login script: user can't hit "return" for login dmerrill Java Basics 13 July 14th, 2006 07:25 PM
Context.User in siteheader.ascx.cs scottf BOOK: ASP.NET Website Programming Problem-Design-Solution 7 November 3rd, 2005 12:52 PM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM





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