日期:2014-05-19  浏览次数:20979 次

请问怎么在程序运行过程中,执行临时读取的一个文本文件中的sql语句?
如题,文本文件中有单独的   select   语句   ,也有create       proc   的存取过程

------解决方案--------------------
@echo off
OSQL -E -i CreateStoredProcedures.sql
echo .
echo Scripts Created

将文本做成.sql可以吗?
------解决方案--------------------
虽然我没做过类似的活,但提问题要写明编程工具啊楼主
关注……
------解决方案--------------------
用c#读文件

using System;

using System.IO;

using System.Collections;

class Anagrams

{

public static void Main(String[] args)

{

StreamReader din = File.OpenText ( "words.txt ");

String str;

StringTable st = new StringTable();

Console.WriteLine( "Reading data and insterting into a StringTable. ");

while ((str=din.ReadLine()) != null) {

st.Add(str);

}

Console.WriteLine( "Printing out the StringTable. ");

foreach (string s in st)

{

Console.WriteLine (s);

}

Console.WriteLine ( "\r\nPress Return to exit. ");

Console.Read();

}

}

将文本读出来再用SqlCommand执行就行了。

------解决方案--------------------
一样滴,sql用 "; "分开就行了。
------解决方案--------------------
如果使用标准sql做成的文本文件的话,可以使用程序调用bcp的方法执行的呵呵
------解决方案--------------------
用脚本写个编义指令应该就可以吧,具体的我忘了怎么写的,可以在网上搜一下。