- 热门文章:
- · .Net下WebMethod属性
- · .NET客户端应用程序:.NET应用程序更新组件(6)
- · .NET客户端应用程序:.NET应用程序更新组件(5)
- · 创建分布式应用程序学习心得
- · 基于组件的.NET软件开发(1)
- · .net关于企业Excel报表的生成
- · 使用 Visual C# .NET 在 ADO.NET 中以编程方式构建连接字符串
- · 让用户通过宏和插件向您的 .NET 应用程序添加功能
- · Visual Basic.NET和GDI+共创图标编辑器
- · Visual Basic .NET 中动态加载类 (三)
- · Visual Basic .NET 中动态加载类 (二)
- · Visual Basic .NET 中动态加载类(一)
在.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(秋枫)
下一篇:.Net下WebMethod属性 >>
相关文章:
- · 我的.Net下应用程序发布问题的简易解决方案
- · 关于自定义事件的一点体会
- · .net 中的事务总结
- · .net中一些所封装的类
- · .Net 下对SqlServer2000中的存储过程的调用
- · .Net 下对SqlServer2000中的存储过程的调用
- · .NET组件和COM组件之间的相互操作
- · 权限管理工具的使用方法
- · .net关于企业Excel报表的生成
- · .NET Test Driven Development
- · 使用 Visual C# .NET 向 Microsoft Excel 2002 传输 XML 数据
- · Remoting编程知识二
- · Remoting编程知识一
- · 在.net中轻松掌握Windows窗体间的数据交互
- · .NET里面的Interop太烂了
- · .NET中的设计模式五:观察者模式
- · .NET Framework 2.0 beta 新特性
- · 把.NET程序部署到没有安装.NET Framwork的机器上
- · 对使用net程序架构开发的一点点儿
- · 在.NET下获取硬盘序列号的问题
- · 在.net中Oracle日期类型的处理
- · 由C++转向C#:我们需要注意哪些方面的变化?
- · 如何保护我们的 .NET 程序集?
- · 初级:.net框架下的MD5
- · .net下软件的自动升级--上传
- · 针对 .NET 框架的安全编码指南
- · .NET框架类命名空间
- · .Net框架程序设计(一)----进阶
- · .NET中的设计模式二:单件模式
- · .Net的注册表操作
- · [GDI+] ColorMatrix 彩色矩阵
- · 在.NET中实现彩色光标,动画光标和自定义光标
- · .Net框架下的XSLT转换技术简介
- · NET Framework 工具
- · 充分利用 .NET 框架的 PropertyGrid 控件
- · 把.NET程序部署到没有安装.NET Framwork的机器上
- · ADO连接数据库字符串大全
- · 在 Visual C# .NET 中建立一个平滑的进度条
