0

I have executed SELECT query to get data form .xls (Ms-EXCEL) file which works fine

 OdbcConnection con = new OdbcConnection("Dsn=XlsDB"); //Created DSN for .xls file
 con.Open();
 OdbcCommand cmd = new OdbcCommand("Select Password from [Users$] where UserName='javed'",con);
 OdbcDataReader dr = cmd.ExecuteReader();
 while (dr.Read())
 {
       if(dr[0].ToString()=="akram")
          MessageBox.Show("Welcome");
 }

BUT

while inserting values in .xls file its giving error

OdbcConnection con = new OdbcConnection("Dsn=XlsDB"); //Created DSN for .xls file
con.Open();

OdbcCommand cmd1 = new OdbcCommand("INSERT INTO [Users$](UserName,Password) VALUES(@name, @pass)", con);
cmd1.Parameters.Add(new OdbcParameter("@name", "hello"));
cmd1.Parameters.Add(new OdbcParameter("@pass", "world"));
cmd1.ExecuteNonQuery();  //error here
1
  • @Peter: ERROR [07002] [Microsoft][ODBC Excel Driver] Too few parameters. Expected 2. Commented Mar 4, 2011 at 18:19

2 Answers 2

1

Take a look at system.data.odbc.odbcparameter and you will see that you are using the odbcparameter class incorrectly.

Sign up to request clarification or add additional context in comments.

Comments

0

I think the parameter names should not contain the @ symbol like...

cmd1.Parameters.Add(new OdbcParameter("name", "hello"));
cmd1.Parameters.Add(new OdbcParameter("pass", "world"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.