Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

I am trying to selct some rows using this code.
When i use
cmd.CommandType = CommandType.TableDirect ;

error coming is too few parameters. and when i use
cmd.CommandType = CommandType.StoredProcedure ;
error is
VB
Unspecified error
Invalid operation
I am using VS 2010 and ms office 2007 on windows
7 platform.

try
            {
                OleDbCommand cmd = new OleDbCommand("byjobtitle", cnn);
                cmd.CommandType = CommandType.TableDirect ;
                OleDbParameter prm = new OleDbParameter("@jobtitle", OleDbType.VarChar, 20);
                prm.Direction = ParameterDirection.Input;
                prm.Value = "Owner";
                cmd.Parameters.Add(prm);
                DataSet ds = new DataSet();
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
                return ds.Tables[0];
            }
            catch (Exception ex)
            { return null; }
            finally { cnn.Close(); }

I have done this before on using VS 2008 ans XP i didnt get any suxh errors. wasted my one day already. Please help.
Posted
Comments
walterhevedeich 25-Aug-11 2:05am    
Is byjobtitle a stored procedure? Can you post it?
snehalgb 25-Aug-11 2:07am    
yes here it is
SELECT Customers.*
FROM Customers
WHERE (((Customers.[Job Title])=[@jobtitle]));
and this is working fine when i execute on ms access db
Yuri Vital 25-Aug-11 3:14am    
your windows 7 is 32 or 64 bits... ?
snehalgb 25-Aug-11 3:38am    
32 bit

Remove arobase "@" from your parameter name and use a stored procedure commandType

ex :
OleDbParameter prm = new OleDbParameter("jobtitle", OleDbType.VarChar, 20);
cmd.CommandType = CommandType.StoredProcedure ;
 
Share this answer
 
v3
Comments
snehalgb 25-Aug-11 6:11am    
Unspecified error
Invalid operation. error is coming again...
Office 2007 doesnt support dataset to be filled with saved query which accepts parameter. The same code for office 2003 is working fine.

Excecutenonquery works fine with param on office 2007.
 
Share this answer
 

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