Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ex = {"ERROR [07002橾] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."}

not getting this ERROR please help to solve this thank you in Adv ..
my code is below ..
C#
protected void txtuname_TextChanged1(object sender, EventArgs e)
{
    try
    {
        if (!string.IsNullOrEmpty(txtuname.Text))
        {

            con.Open();
            OdbcCommand cmd = new OdbcCommand("select U_name from LOGIN where U_name=@Name", con);
            cmd.Parameters.AddWithValue("@Name", txtuname.Text);
            OdbcDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                checkusername.Visible = true;
                imgstatus.ImageUrl = "Image/NotAvailable.jpg";
                lblStatus.Text = "UserName Already Taken Please Try Another Name For Example:Bharat123/Bharat89";
                System.Threading.Thread.Sleep(2000);
                txtuname.Text = string.Empty;
            }
            else
            {
                checkusername.Visible = true;
                imgstatus.ImageUrl = "Image/Icon_Available.gif";
                lblStatus.Text = "UserName Available";
                System.Threading.Thread.Sleep(2000);
            }
        }
        else
        {
            checkusername.Visible = false;
        }
    }
    catch (Exception ex)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('ERROR,Please try again if this error occurs again please mail us on Contact Us page , Thank You')", true);

    }
}
Posted
v3
Comments
CHill60 8-May-13 6:13am    
First things to check are:-
1. Is there a column in table LOGIN called U_name (spelled exactly like that)
2. Does txtuname.Text contain anything
Amirsalgar1 8-May-13 6:16am    
thanx for the reply sir,
yup i was working successfully .. before creating dsn
but now it is showing me error
CHill60 8-May-13 6:22am    
Which implies that there is a problem with your dsn ... use Improve question link to post how you are connecting to the access database
Amirsalgar1 8-May-13 6:51am    
it is connected correctly sir,
it is occurring with Login page only
Amirsalgar1 8-May-13 6:17am    
txtuname is contain username .. which is autopostback which is checking that username is exist in database or not

1 solution

ODBC and SQL work differently

The parameter in the query should be a q-mark '?'
The parameters can be any unique name and must be added to the collection in the same order as the q-marks they should replace appear in the query

i.e.
C#
string q = "select * from t_able where a = ? and b = ?";

OdbcCommand cmd = new OdbcCommand(q, con)

cmd.Parameters.AddWithValue("ParamA", aValue);
cmd.Parameters.AddWithValue("ParamB", bValue);


Even when you wish to use the same parameter twice in the same query, you will have to add two parameters with unique names and the same value.

This is because ODBC is much more generic that TSQl which used the '@*' style parameters
 
Share this answer
 
Comments
Amirsalgar1 9-May-13 2:40am    
thanks a lot sir now its working :) thanks again ..god bless

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900