Lets say I have following in my MyScript.Sql file
declare @city char(10)
set @city = 'Berlin'
If EXISTS( SELECT * FROM Customer where city = @city)
begin
---some stuff to do with the record---
end
using following code, i'm able to run above .sql file.
string sqlConnectionString = @"MyCS";
FileInfo file = new FileInfo(@"(location of .sql file");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
file.OpenText().Close();
Now, I want to be able to dynamically pass the value of @city from my C# code to the .sql script instead of setting it's value in .sql file itself. How can I do that? Thanks!