使用C#連結Ms SQL並且列出指定DB內的所有資料表名稱
使用C#連結Ms SQL並且列出指定DB內的所有資料表名稱
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; namespace CS_Console_MsSQL { class Program { static { Console.Write(“Press any key to continue . . . “); Console.ReadKey(true); } static { //http://livin.tw/?p=555 //第A一@:G連s結g2SQL資Me料A庫w String String String String String SqlConnection conn.Open(); //http://stackoverflow.com/questions/3005095/can-i-get-name-of-all-tables-of-sql-server-database-in-c-sharp-application DataTable List<string> tables = new foreach { string tables.Add(tablename); Console.WriteLine(tablename); } /* //第A二G:G執Xo行aSQL指u令DO string sqlstr = SqlCommand cmd = new SqlDataReader dr = //第A三T:G印L出DX資Me料A while (dr.Read()) { String s = } //第A四D|:G關o閉?連s線u cmd.Cancel(); dr.Close(); */ Pause(); conn.Close(); conn.Dispose(); } } } |