读取文件,替换单词,然后在SQL中执行 [英] Read a file ,replace words and then execute in SQL

查看:95
本文介绍了读取文件,替换单词,然后在SQL中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个sql文件。我想读取文件替换它中的一些单词,然后在SQL服务器中执行。这是一个例子。



Hi,

I have a sql file. i want to read the file replace some words in it and then execute in SQL server. Here is an example.

INSERT INTO [destinationDBName].dbo.[devicemake](id,name,isactive,provid)
(select id,Make,1,ID from [sourceDBName].dbo.DeviceMake)





该文件可能包含10个这样的查询,我想阅读每个查询并执行它们。在执行之前我想用GUI中提供的值替换[destinationDBName],[sourceDBName]的情况也一样。请帮助



THe file may contain 10 queries like this and i want to read each query and execute them . Before executing i want to replace [destinationDBName] with values i provide in GUI , same is the case with [sourceDBName] .. Pls help

推荐答案

你能不能只是将值作为参数传递?



http://askanantha.blogspot.co.uk/2007/09/how-do-i-pass-parameters-to-sql-file.html [ ^ ]
Can''t you just pass the values in as parameters?

http://askanantha.blogspot.co.uk/2007/09/how-do-i-pass-parameters-to-sql-file.html[^]


string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()。Location);



字符串查询= File.ReadAllText(路径);
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

string queries = File.ReadAllText(path);


这篇关于读取文件,替换单词,然后在SQL中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆