Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET MS-Access
I am desiging a change password screen in ASP.Net,C#,MS-Access database. I'm have 4 fields: userid, oldpassword, newpassword, confirm password. I wrote some code but am getting an error.
 
Error: The type 'System.Data.OleDb.OleDbDataReader' has no constructors defined
 
My code is as follows:
try
 
      {
 
      OleDbConnection myCon = new  OleDbConnection(ConfigurationManager.ConnectionStrings["vhgroupconnection"]
       .ConnectionString);
        myCon.Open();
 
        string userid = txtuserid.Text;
        string oldpass = txtoldpass.Text;
        string newPass = txtnewpass.Text;
        string conPass = txtconfirmpass.Text;
 
        string q = "select user_id,passwd from register where user_id = @userid and       passwd = @oldpass";
 
        OleDbCommand cmd = new OleDbCommand(q, myCon);
 
        OleDbDataReader re = new OleDbDataReader();
 
        cmd.Parameters.AddWithValue("@userid", txtuserid.Text);
 
        cmd.Parameters.AddWithValue("@oldpass", txtoldpass.Text);
 
        re = cmd.ExecuteReader();
 
        re.Read();
 
        if (re["user_id"].ToString() != String.Empty && re["passwd"].ToString() != String.Empty)
        {
            if (newPass.Trim() != conPass.Trim())
            {
                lblmsg.Text = "New Password and old password does not match";
 
            }
            else
            {
                q = "UPDATE register SET passwd = @newPass WHERE user_id =@userid";
                cmd = new OleDbCommand(q, myCon);
                cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text);
                cmd.Parameters.AddWithValue("@userod", txtuserid.Text);
                cmd.Parameters.AddWithValue("@passwd", txtoldpass.Text);
 
                int count = cmd.ExecuteNonQuery();
 
                if (count > 0)
                {
                    lblmsg.Text = "Password changed successfully";
                }
                else
                {
                    lblmsg.Text = "password not changed";
                }
            }
        }
    }
    catch(Exception ex)
    {
        throw ex;
    }
 
Please help me to solve the problem.
Posted 17-Apr-13 8:56am
Edited 17-Apr-13 9:02am
v2
Comments
ThePhantomUpvoter at 17-Apr-13 14:00pm
   
OleDbDataReader re = cmd.ExecuteReader();
 
Reading the documentation helps a lot in these types of situations.
richcb at 17-Apr-13 14:04pm
   
Post that as the answer, it is correct.
ThePhantomUpvoter at 17-Apr-13 14:16pm
   
Done. Thanks.... too much like work :-)
Devendra Dighe at 17-Apr-13 14:05pm
   
i tried it
but when i debugged the code it showed exception as
ex {"No value given for one or more required parameters."} System.Exception {System.Data.OleDb.OleDbException}
ThePhantomUpvoter at 17-Apr-13 14:09pm
   
The error has absolutely nothing to do with your current question. You are getting that error because you are passing an UPDATE statement with 3 parameters but your statement only makes use of 2.
Devendra Dighe at 17-Apr-13 14:24pm
   
here is what i made chages but got exception ex {"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."} System.Exception {System.Data.OleDb.OleDbException}
 
my updated code is
 
OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["vhgroupconnection"].ConnectionString);
myCon.Open();
 
string userid = txtuserid.Text;
string oldpass = txtoldpass.Text;
string newPass = txtnewpass.Text;
string conPass = txtconfirmpass.Text;
 
string q = "select user_id,passwd from register where user_id = @userid and passwd = @oldpass";
OleDbCommand cmd = new OleDbCommand(q, myCon);

cmd.Parameters.AddWithValue("@userid", txtuserid.Text);
cmd.Parameters.AddWithValue("@oldpass", txtoldpass.Text);
OleDbDataReader re = cmd.ExecuteReader();
re.Read();
 
if (re["user_id"].ToString() != String.Empty && re["passwd"].ToString() != String.Empty)
{
if (newPass.Trim() != conPass.Trim())
{
lblmsg.Text = "New Password and old password does not match";
 
}
else
{
q = "UPDATE register SET passwd = @newPass WHERE user_id =@userid";
cmd = new OleDbCommand(q, myCon);
cmd.Parameters.AddWithValue("@userid", txtuserid);
cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text);
//cmd.Parameters.AddWithValue("@userod", txtuserid.Text);
// cmd.Parameters.AddWithValue("@passwd", txtoldpass.Text);
 
int count = cmd.ExecuteNonQuery();
 
if (count > 0)
{
lblmsg.Text = "Password changed successfully";
}
else
{
lblmsg.Text = "password not changed";
}
 

in my database
user_id,passwd
Devendra Dighe at 17-Apr-13 14:42pm
   
I m not getting solution
 
is thr anyother solution for the problem plz suggest me
ThePhantomUpvoter at 17-Apr-13 16:39pm
   
And still none of this has anything to do with your current question. This is a totally separate question
Amirsalgar1 at 17-Apr-13 14:12pm
   
Check out your database names ..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to delete the line:
OleDbDataReader re = new OleDbDataReader();
because that class does not have a constructor. Which is exactly what the error is telling you. The reader is instantiate by calling ExecuteReader, http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.aspx[^]
 
Change:
re = cmd.ExecuteReader();
to
OleDbDataReader re = cmd.ExecuteReader();
 
Your other error is caused by your SQL statement.
"UPDATE register SET passwd = @newPass WHERE user_id =@userid";
Were you are adding 3 parameters but only using 2 in your statement. Either add the other parameter to your statement or get rid of adding the other parameter.
  Permalink  
Comments
richcb at 17-Apr-13 14:17pm
   
That's a two for one. You solved the original issue of the OP which unveiled another and you got that one as well. +5.
ThePhantomUpvoter at 17-Apr-13 14:23pm
   
Thanks
Devendra Dighe at 17-Apr-13 15:06pm
   
@ThePhantomUpvoter: i changed the code but its now returning else part of the codeing i.e password was not changed its returning count=0
here is my update query
q = "UPDATE register SET passwd = @newPass WHERE user_id =@userid";
cmd = new OleDbCommand(q, myCon);
cmd.Parameters.AddWithValue("@userid", txtuserid.Text);
cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text);


 
int count = cmd.ExecuteNonQuery();
 
if (count > 0)
{
lblmsg.Text = "Password changed successfully";
}
else
{
lblmsg.Text = "password not changed";
}
ThePhantomUpvoter at 17-Apr-13 16:29pm
   
Is user_id an int? Get the actual SQL text from your command object and see if that works directly in your database.
Devendra Dighe at 18-Apr-13 10:26am
   
No my user_id is not integer its text
Devendra Dighe at 18-Apr-13 12:40pm
   
I GOt the answer i changed my update query as:
 
q = "UPDATE register SET passwd = '"+txtnewpass.Text+"' WHERE user_id ='"+txtuserid.Text+"'";
 
it worked successfully
 
thank you for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 544
2 Maciej Los 325
3 DamithSL 223
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100