#2
wube2018-01-29 18:14
试出来查询笔数指令是 ...
Select COUNT(*) FROM [AAA] where [Time]='2018-01-29' 取得之资料笔数及将资料存入阵列只找到C#版没VB的... 看不懂... http://blog.(table+to+array) c# 將資料表取出放到陣列 (table to array) using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data; //使用DataTable必須的 using System.Data.SqlClient; //取得SqlClient相關物件必須的 using System.Globalization; public partial class Update : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //建立連線物件 ConnectionStringSettings WORKFLOWGP = ConfigurationManager.ConnectionStrings["WORKFLOWGP"]; SqlConnection conn = new SqlConnection(); conn.ConnectionString = WORKFLOWGP.ConnectionString; conn.Open(); string queryStr = "SELECT TD001+'-'+RTRIM(TD002)+'-'+TD003,TD015 FROM PURTC INNER JOIN PURTD ON TC001 = TD001 AND TC002 = TD002 WHERE TD016 = 'N' AND TC014 = 'Y'"; SqlDataAdapter oda = new SqlDataAdapter(queryStr, conn); DataTable dt = new DataTable("PURTD"); //利用SqlDataAdapter的Fill方法將DB取出的data塞入DataTable中,再利用DataTable取出值 oda.Fill(dt); //從DB Load Data到Array object[][] LoadData = new object[dt.Rows.Count][]; for (int i = 0; i < dt.Rows.Count; i++) { LoadData[i] = new object[dt.Columns.Count]; for (int j = 0; j < dt.Columns.Count; j++) { LoadData[i][j] = dt.Rows[i][j].ToString(); } } //最後將收集起來的資料存取在陣列中 //Object[][] LoadData = listResult.ToArray(); |
如何取得查询数据库后取得之资料笔数及将资料存入阵列中?