社区
C#
帖子详情
C#中怎样执行含有SQL语句的.sql文件啊?
xyusong
2005-05-11 03:06:57
我写了一些SQL语句并且把它放在了mysql.sql文件中,请问在C#中怎样执行我写在mysql.sql中的SQL语句啊?
谢谢le!!!
...全文
587
7
打赏
收藏
C#中怎样执行含有SQL语句的.sql文件啊?
我写了一些SQL语句并且把它放在了mysql.sql文件中,请问在C#中怎样执行我写在mysql.sql中的SQL语句啊? 谢谢le!!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
conan19771130
2005-05-20
打赏
举报
回复
先读出来,在执行那个
shanminmin
2005-05-20
打赏
举报
回复
sql文件不用在sql server服务器上,就用sqlcmmand执行就行了。还有你也可以直接调用执行
tsql 文件名.sql
这种方式。
realljx
2005-05-19
打赏
举报
回复
那如果我的SQL语句并不在SQL服务器上呢?
marvelstack
2005-05-12
打赏
举报
回复
using System;
using System.Data;
using System.Collections;
using System.Xml;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace Zhzuo
{
public class ZZConsole
{
[STAThread]
static void Main(string[] args)
{
//测试
//string vv = ExeCommand("dir");
//Console.WriteLine(vv);
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执行Sql语句。
用法: 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
例如:
osql.exe /uSa /p123 /s192.192.132.229 /dNorthWind /i yoursql.sql
ms-help://MS.MSDNQTR.2003FEB.2052/vsintro7/html/vxwlkwalkthroughusingcustomactiontocreatedatabaseduringinstallation.htm
niunj
2005-05-11
打赏
举报
回复
对阿 肯定是在ado.net中运行这些相当于文本的一些命令而已。
chenyun122
2005-05-11
打赏
举报
回复
//从文件中提取SQL指令
private string GetSqlFile(string FilePath)
{
string input;
string Command
StreamReader sr;
sr = new StreamReader(FilePath,System.Text.Encoding.Default);
while ((input=sr.ReadLine())!=null)
{
Command = Command + " \n " + input;
}
sr.Close();
return Command;
}
skyeenet
2005-05-11
打赏
举报
回复
当成string 读成字符串 然后用 sqlcommand 执行不一样么?
Oracle批处理:使用
C#
自带Oracle驱动一次
执行
多条
Sql
语句
Oracle批处理:使用
C#
自带Oracle驱动一次
执行
多条
Sql
语句
access 一次
执行
多条
sql
语句
access 一次
执行
多条
sql
语句
! 值得下载看看!资源免费,大家分享!! 更多免费资源 http://ynsky.download.csdn.net/
C#
SQL
查询技术
本课程以
SQL
Server 2008 R2数据库系统为例,全面介绍
SQL
查询技术,包括select语句,Where子句,Order By子句,Group By子句,having语句,TOP和PERCENT限制查询结果,在查询
中
使用OR和AND运算符,聚合函数应用,多表连接查询,嵌套查询,子查询,联合语句Union,内联接、外联接查询,交叉表查询,视图、存储过程的应用,触发器的应用等。
sql
语句
妙用,各种
sql
语句
的详细用法与讲解
sql
语句
妙用,各种
sql
语句
的详细用法与讲解 ,使得程序运行的更加流畅。主要针对一些高效
sql
语句
的解释。
sql
editor 一个用
c#
写的db2客户端工具(原创)
一个用.net2.0写的db2数据库客户端工具支持代码提示,支持批量
执行
sql
,支持单表查询下的全表格编辑,支持导出excel和insert语句。自己写的用着就是比较爽,呵呵,需要.net2.0的支持
C#
110,545
社区成员
642,580
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章