国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

在.net執行sql腳本的簡單實現

2024-07-10 12:59:16
字體:
來源:轉載
供稿:網友
在.net執行sql腳本的簡單實現

鄭佐2004-12-25

看到csdn社區經常有人問在.net中如果執行sql腳本,下面是使用c#調用cmd來執行osql實現腳本的執行。



using system;

using system.data;

using system.collections;

using system.xml;

using system.io;

using system.text;

using system.diagnostics;



namespace zz

{

public class zzconsole

{

[stathread]

static void main(string[] args)

{

string sqlquery = "osql.exe /usa /p123 /s192.192.132.229 /dnorthwind /i yoursql.sql";

string strrst = execommand(sqlquery);

console.writeline(strrst);

console.readline();

}



public static string execommand(string commandtext)

{

process p = new process();

p.startinfo.filename = "cmd.exe";

p.startinfo.useshellexecute = false;

p.startinfo.redirectstandardinput = true;

p.startinfo.redirectstandardoutput = true;

p.startinfo.redirectstandarderror = true;

p.startinfo.createnowindow = true;

string stroutput = null;

try

{

p.start();

p.standardinput.writeline(commandtext);

p.standardinput.writeline("exit");

stroutput = p.standardoutput.readtoend();

p.waitforexit();

p.close();

}

catch(exception e)

{

stroutput = e.message;

}

return stroutput;

}

}

}



對于osql命名的參數如下:

=====================



用法: osql [-u login id] [-p password]

[-s server] [-h hostname] [-e trusted connection]

[-d use database name] [-l login timeout] [-t query timeout]

[-h headers] [-s colseparator] [-w columnwidth]

[-a packetsize] [-e echo input] [-i enable quoted identifiers]

[-l list servers] [-c cmdend] [-d odbc dsn name]

[-q "cmdline query"] [-q "cmdline query" and exit]

[-n remove numbering] [-m errorlevel]

[-r msgs to stderr] [-v severitylevel]

[-i inputfile] [-o outputfile]

[-p print statistics] [-b on error batch abort]

[-x[1] disable commands [and exit with warning]]

[-o use old isql behavior disables the following]

[-? show syntax summary]

具體參考

http://www.588188.com/netbook/sqlserver2000/coprompt/cp_osql_1wxl.htm

或者sql server 2000幫助文檔



上面程序是我以前在csdn回答問題時寫的,由于最近比較忙,所以偷懶了。對于本文有什么好的建議或意見請留言。zhzuo(秋楓)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂尔多斯市| 元谋县| 南溪县| 青海省| 扎兰屯市| 饶平县| 南溪县| 西华县| 普兰店市| 祁门县| 拉萨市| 西畴县| 得荣县| 福建省| 怀远县| 遵化市| 当阳市| 新巴尔虎右旗| 金乡县| 乐亭县| 山阴县| 沂水县| 富宁县| 拉孜县| 临漳县| 孝昌县| 清涧县| 达州市| 无棣县| 莲花县| 乐平市| 河北区| 丹凤县| 新泰市| 白沙| 肇庆市| 朝阳区| 乐平市| 建始县| 祥云县| 新津县|