Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# 2005 and VFPOLE with parameters
Message
From
03/12/2005 10:26:21
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01074551
Message ID:
01074578
Views:
13
The ? in the select string is correct, but when adding the parameters, you need to use an @. So, it would be:
	VFP7SelectCommand.Parameters.AddWithValue("@mylogin",pLoginName);
	VFP7SelectCommand.Parameters.AddWithValue("@mypass", pPassword);
~~Bonnie



>I am trying to do a simple query from a VFP table into C# using a VFPOLE connection. I can get the table to pull over completely into a DataAdapter without any parameters, but as soon as I introduce parameters, I get 0 records (and I know there should be at least one). This has to be a rather simple problem; can anyone steer me in the right direction?
>
>
>        string pTable = "csrcli.dbf";
>	string pSQLcommand = "Select * from csrcli where loginname = ? and password = ?";
>
>        OleDbConnection VFP7Connection = new OleDbConnection();
>        string l_conn = "provider=VFPOLEDB.1;DATA SOURCE=" + Server.MapPath("csr.dbc") +
>               ";Exclusive=NO;Backgroundfetch=NO";
>	VFP7Connection.ConnectionString = l_conn;
>
>		
>	//build command object to pass through connection
>	string strSelect = pSQLcommand;
>	//OleDbCommand VFP7SelectCommand;
>	OleDbCommand VFP7SelectCommand = new OleDbCommand();
>	VFP7SelectCommand.CommandText = strSelect;
>	VFP7SelectCommand.Parameters.AddWithValue("?mylogin",pLoginName);
>	VFP7SelectCommand.Parameters.AddWithValue("?mypass", pPassword);
>
>	VFP7Connection.Open();
>
>	//create a DataAdapter
>	OleDbDataAdapter VFP7DataAdapter = new OleDbDataAdapter();
>	VFP7DataAdapter.SelectCommand = VFP7SelectCommand;
>	VFP7DataAdapter.SelectCommand.Connection = VFP7Connection;
>		
>	//create the dataset
>	DataSet VFP7DataSet = new DataSet();
>	//fill the dataset (finally!)
>	VFP7DataAdapter.Fill(VFP7DataSet,pTable);
>	return VFP7DataSet;
>
>
>This simple task has wasted a whole day of research, trial & error. I would be most grateful if someone could help me get past this problem!!!!!
>
>Thanks!
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform