how do i handle this exception

N

NITIN MUNJAL

hello, i am facing a problem in the runtime. this code is throwing
exception details of which are writtten below that

CODE

string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" +
Server.MapPath("/db.mdb");
OleDbConnection myConn = new OleDbConnection(strConn) ;
string strCon ="SELECT email FROM authenticate WHERE uname="+uname ;
OleDbCommand vicomm = new OleDbCommand(strCon, myConn) ;
myConn.Open();
OleDbDataReader reader ;
reader = vicomm.ExecuteReader() ;
reader.Read() ;
string email = reader.GetString(0) ;
reader.Close();
myConn.Close();

EXCEPTION DETAILS

Exception Details: System.Data.OleDb.OleDbException: No value given
for one or more required parameters.
Line 25: reader = vicomm.ExecuteReader() ;



WHAT I AM TRYING TO DO IS TO RETRIEVE THE EMAIL ADDRESS OF THE PERSON
GIVEN HIS USERNAME

TIA
NITIN
 
K

Karl Seguin

Not sure but maybe it's because you aren't wrapping uname in single quotes
(which I assume it's a string).
Also, plz use parameterized queries, which you can do without having to use
stored procedures. This will make your code more readable, secure and
flexible:

strCon = "SELECT email FROM authenticate where uname = @uname";
OleDbCommand vicomm = new OleDbCommand(strCon, myConn)
vicomm.Parameters.Add("@Uname", OleDbType.VarChar).Value = uname;

Karl
 
N

NITIN MUNJAL

well i am a newbie in this...am doing a project implementing a
discussion board....and had got frustated because of this
exception..but my code was based on what was given on the msdn
site........
i am really relieved now....thanks a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top