I want to execute a SQL query from my C# project. My problem is that I use in the query the connection string, which includes \. I have to escape it but the SQL can't get \\. I tried use @, but it still didn't work.
My SQL Query looks like:
INSERT INTO [SQL_TABLE]
SELECT *
FROM [Provider = Microsoft.Jet.OLEDB.4.0; Data Source
=Y:\\MyAccess\\MyDB\\myAccessFile.mdb; Jet OLEDB:Database Password =
1234;].[ACCESS_TABLE]
WHERE [ID] = 1234
The SQL get it with \\, but accept \.
I have tried even:
for(int i = 0;i < dt.Rows.Count; i++)
{
try
{
string selectSQL = "SELECT *
FROM [" + @"Provider = Microsoft.Jet.OLEDB.4.0;
Data Source
=Y:\MyAccess\MyDB\myAccessFile.md; Jet
OLEDB:Database Password = 1234;].
[VTblASMCustomersDocumentsAndGroupCodes]
WHERE [ID] = 1234"
string sql = "INSERT INTO [SQL_TABLE] " + selectSQL;
executeSQLQuery(sql, connectionStringSQL);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
What should I do?
INSERT, and ACCESS DB in theSELECT.@, which makes \ not reuqire to be escaped. You surely have problem somewhere else.@?