假设我在MyScript.Sql文件中有以下内容:
使用以下代码,我可以运行上述的.sql文件。
declare @city char(10)
set @city = 'Berlin'
If EXISTS( SELECT * FROM Customer where city = @city)
begin
---some stuff to do with the record---
end
使用以下代码,我可以运行上述的.sql文件。
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();
现在,我希望能够从我的C#代码动态地传递@city的值给.sql脚本,而不是在.sql文件中设置它的值。我该如何做到这一点呢?谢谢!