Loading ...

Error in the coding

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » Error in the coding

Error in the coding

Posts under the topic: Error in the coding

Posted: 6/15/2010

Lurker 5  points  Lurker
  • Joined on: 6/15/2010
  • Posts: 1

there is an error in code. i have taken DataTable to fill it with the query passed to oledb but it is showing ola.Fill(dt)-  No value given for one or more required parameters. kindly help with this code

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

protected void btnSign_Click(object sender, EventArgs

e)

{

 

 

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\New folder12\\Desktop\\SWAPNALI\\Database3.mdb"

);

con.Open();

 

 

string strquery = "Select * from Table1 WHERE Name='"+txtName.Text+"' AND Password='"+txtPwd.Text+"'"

;

 

 

DataTable dt = new DataTable

();

 

 

OleDbDataAdapter oda = new OleDbDataAdapter

(strquery, con);

oda.Fill(dt);

 

 

if

(dt.Rows.Count > 0)

Response.Redirect(

 

"Home.aspx?name="

+txtName.Text);

 

 

else

Response.Redirect(

 

"Error.aspx"

);


Posted: 6/15/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391
  Answered

I suspect your OleDbDataAdapter is confused. Seems its searching for parameters.

I have tested it and it works fine on my machine.

Try to rewrite your code on the following way:

        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\New folder12\\Desktop\\SWAPNALI\\Database3.mdb");
        OleDbCommand cmd = new OleDbCommand("Select * from Table1 WHERE Name=@username AND Password=@password",con);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@username", txtName.Text);
        cmd.Parameters.AddWithValue("@password", txtPwd.Text);
                
        OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
        DataTable dt = new DataTable();
        con.Open();
        oda.Fill(dt);
        con.Close();

        if (dt.Rows.Count > 0)
            Response.Redirect("Home.aspx?name=" + txtName.Text);
        else
            Response.Redirect("Error.aspx");

Hope this helps.


Page 1 of 1 (2 items)