vb.net
Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Dim table As DataTable = dv.Table
Console.WriteLine(label)
' Loop through each row in the view.
For Each rowView As DataRowView In dv
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(rowView(col.ColumnName).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
Private Sub PrintTableOrView(ByVal table As DataTable, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Console.WriteLine(label)
' Loop through each row in the table.
For Each row As DataRow In table.Rows
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(row(col).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
C#
private static void PrintTableOrView(DataView dv, string label)
{
System.IO.StringWriter sw;
string output;
DataTable table = dv.Table;
Console.WriteLine(label);
// Loop through each row in the view.
foreach (DataRowView rowView in dv)
{
sw = new System.IO.StringWriter();
// Loop through each column.
foreach (DataColumn col in table.Columns)
{
// Output the value of each column's data.
sw.Write(rowView[col.ColumnName].ToString() + ", ");
}
output = sw.ToString();
// Trim off the trailing ", ", so the output looks correct.
if (output.Length > 2)
{
output = output.Substring(0, output.Length - 2);
}
// Display the row in the console window.
Console.WriteLine(output);
}
Console.WriteLine();
}
private static void PrintTableOrView(DataTable table, string label)
{
System.IO.StringWriter sw;
string output;
Console.WriteLine(label);
// Loop through each row in the table.
foreach (DataRow row in table.Rows)
{
sw = new System.IO.StringWriter();
// Loop through each column.
foreach (DataColumn col in table.Columns)
{
// Output the value of each column's data.
sw.Write(row[col].ToString() + ", ");
}
output = sw.ToString();
// Trim off the trailing ", ", so the output looks correct.
if (output.Length > 2)
{
output = output.Substring(0, output.Length - 2);
}
// Display the row in the console window.
Console.WriteLine(output);
} //
Console.WriteLine();
}
感謝
http://msdn.microsoft.com/zh-tw/library/73kk32zz(v=vs.80).aspx#
熱門文章
-
DECLARE @ID AS INT DECLARE @LastCust AS VARCHAR(50) DECLARE @LastReceiveTime AS DATETIME SET @ThisCust = ''
-
SELECT DISTINCT GroupField1, COUNT(*) AS CountField FROM SourceTableName GROUP BY GroupField1 HAVING COUNT(*) > 1 ORDER BY CountField
-
----以相同GroupField為組,依據SortField排序,並給予排名RANK SELECT RANK() OVER (PARTITION BY SourceTableName.GroupField ORDER BY SourceTableName1.SortField1...
-
DataTable,DataView和DataGrid中一些容易混淆的概念 一、DataTable DataTable表示內存中數據的一個表,它完全是在內存中的一個獨立存在,包含了這張表的全部信息。DataTable可以是從通過連接從數據庫中讀取出來形成的一個表,一旦將內容讀到D...
-
StrA + StrB
-
vb.net Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String) Dim sw As System.IO.StringWriter Dim output As Stri...
-
--宣告Cursor的資料來源Table DECLARE vendor_cursor CURSOR FOR SELECT Field1, Field2, Field3 FROM SourceTableName WHERE Field4 IN ( SELECT DISTINCT ...
-
IF PATINDEX('%' + @pattern + '%', @Expression) = 0 找不到 IF PATINDEX('%' + @pattern + '%', @Expression) = 1 字串...
-
網路簡介與指令
-
IIS 6 iisapp /a DefaultAppPool /r c:\windows\system32\iisapp.vbs /a YourPoolName /r cscript.exe c:\windows\system32\iisapp.vbs /a YourPoolNa...