How to execute. SQL SERVER (transfer) in C #

xiaoxiao2021-03-06  73

I don't like to use osql.exe, isql.exe, although N earlier, use Osql.exe to query the SQL Server server in the LAN. ADO.NET is enough. As long as "Go" is filtered. As follows: use system; use system.data; using system.io; using system.collections; using system.data.sqlclient; Namespace ExecuteSqlfile {////

/// DBACCESS summary.

/// public class dbaccess {public dbaccess () {} #region attribute 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;. string database = doc.SelectSingleNode ( "ServerConfig / DataBase") InnerText;. ConStr = "server =" servername "; uid =" userid "; pwd = " password "; database = " database;} catch (Exception ex) {throw ex;}} return ConStr;}} private static SqlConnection Con; public static SqlConnection MyConnection {get {if (Con == null) {Con = New SqlConnection (Constring);} Return Con; } #Endregion ///

/// Execute SQL file /// /// /// public static bool ExecuteSqlFile (string varFileName) {if {return false (File.Exists (varFileName)!);} StreamReader sr = File.OpenText (varFileName); ArrayList alSql = new ArrayList (); string commandText = ""; string varLine = "" WHILE (sr.peek ()> -1) {varline = sr.readline (); if (varline == "

转载请注明原文地址:https://www.9cbs.com/read-90503.html

New Post(0)