I am declaring a string that is basically a list of designators, where yy is alpha and xxxx is numeric.
string sMyString = "('yy-xxxx','yy-xxxx','yy-xxxx','yy-xxxx','yy-xxxx','yy-xxxx')";
if(File.Exists(sFileLocation + sFileName))
{
txtRunning.Text = "Starting db copy";
File.Copy(sFileLocation + sFileName, sFileName, true);
File.Copy(sDbLocation + "clipper.dbf", "clipper.dbf", true);
File.Copy(sDbLocation + "clipper.dbt", "clipper.dbt", true);
txtRunning.Text = "Starting datatable population";
string connString = @"Provider=VFPOLEDB;Data source=.\clipper.dbf";
string mySelectQuery = "SELECT UPPER(TRIM(field1))," +
" UPPER(TRIM(field2)), UPPER(TRIM(field3)), UPPER(TRIM(field4))" +
" FROM `clipper` WHERE condition1 AND field1 IN " + sMyString +
" ORDER BY field2;";
DataTable dtClipper = new DataTable();
DataTable dtNotFound = new DataTable();
DataTable dTable = new DataTable();
OleDbConnection conn = new OleDbConnection(connString);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(mySelectQuery, conn);
adapter.Fill(dtClipper);
}
If I take out the parens, I get an error in a dataadapter.fill command, saying the function does not exist. I get the same error if I change it to a string literal, with or without the parens. If I leave it as is, with the parens and single quotes, it runs just fine.
I need it to be just the list, without the single quotes as I’m adding them to a dictionary to use as an incidence counter. What is it I’m missing?
That error is because you are using that string to run a SQL query, and without the quotes and parens, it’s invalid sql.
You need to retain the quotes and parens in order for your SQL query to work. If you also need to have access to the list as plain strings, then store it as a list.