我用C#.NET 怎么在程序中调用*.sql文件?

来源:百度知道 编辑:UC知道 时间:2024/06/06 21:46:28
主要是程序中有个按键,点击后执行某个*.SQL的文件。具体方法是怎么写代码的?

using System;
using System.Xml;
using System.Data;
using System.IO;
using System.Collections;
using System.Data.SqlClient;

namespace ExecuteSqlFile
{
/// <summary>
/// DBAccess 的摘要说明。
/// </summary>
public class DBAccess
{
public DBAccess()
{
}

#region 属性

private static string ConStr = "";

private static string ConString
{
get
{
if(ConStr == "")
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load("ServerConfig.xml");

string userid = doc.SelectSingleNode("ServerConfig/UserId").InnerText;
string password = doc.SelectSingleNode("ServerConfig/PassWord").InnerText;
string servername = doc.SelectSingleNode("ServerConfig/ServerName").InnerText;