|
|
 | | From: | =?Utf-8?B?WElBWkhJR0FORw==?= | | Subject: | =?Utf-8?B?5oiR5aaC5L2V5omN6IO95b6X5YiwRGF0YVNldOS4reihqOeahOafkA==?= | | Date: | Thu, 20 Jan 2005 18:13:01 -0800 |
|
|
 | 鎴戝浣曟墠鑳藉緱鍒癉ataSet涓〃鐨勬煇涓琛屾煇涓鍒楃殑鍊煎晩锛
|
|
 | | From: | nicholas | | Subject: | Re: 我如何才能得到DataSet中表的某一行某一列的值啊? | | Date: | Mon, 24 Jan 2005 09:27:00 +0800 |
|
|
 | DataSet.Tables[0].Rows[i][j] "XIAZHIGANG" 写入邮件 news:552BE6C6-A6DE-4513-B3E7-23E2652BBEDC@microsoft.com... > 我如何才能得到DataSet中表的某一行某一列的值啊?
|
|
 | | From: | Vince Yuan | | Subject: | Re: 我如何才能得到DataSet中表的某一行某一列的值啊? | | Date: | Fri, 21 Jan 2005 11:17:25 +0800 |
|
|
 | from MSDN:
Example [Visual Basic, C#, C++] The following example consists of several methods that, combined, create and fill a DataSet from the Northwind database installed as a sample database with SQLServer 7.0. [Visual Basic] Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Drawing Imports System.ComponentModel Imports System.Windows.Forms
public class DataGridSample Inherits Form Private ds As DataSet Private myGrid As DataGrid
Shared Sub Main Application.Run(new DataGridSample()) End Sub
public Sub New() InitializeComponent() End Sub
public Sub InitializeComponent() Me.ClientSize = new Size(550, 450) myGrid = new DataGrid() myGrid.Location = new Point (10,10) myGrid.Size = new Size(500, 400) myGrid.CaptionText = "Microsoft .NET DataGrid" Me.Controls.Add(myGrid) Me.Text = "Visual Basic Grid Example" ConnectToData() myGrid.SetDataBinding(ds, "Suppliers") End Sub
Private Sub ConnectToData() ' Create the ConnectionString and create a SqlConnection. ' Change the data source value to the name of your computer. Dim cString As string = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer" Dim cnNorthwind As SqlConnection = new SqlConnection(cString) ' Create a SqlDataAdapter for the Suppliers table. Dim adpSuppliers As SqlDataAdapter = new SqlDataAdapter() ' A table mapping tells the adapter what to call the table. adpSuppliers.TableMappings.Add("Table", "Suppliers") cnNorthwind.Open() Dim cmdSuppliers As SqlCommand = _ new SqlCommand("SELECT * FROM Suppliers", cnNorthwind) cmdSuppliers.CommandType = CommandType.Text
adpSuppliers.SelectCommand = cmdSuppliers Console.WriteLine("The connection is open.") ds = New DataSet("Customers") adpSuppliers.Fill(ds) ' Create a second SqlDataAdapter and SqlCommand to get ' the Products table, a child table of Suppliers. Dim adpProducts As SqlDataAdapter = new SqlDataAdapter() adpProducts.TableMappings.Add("Table", "Products") Dim cmdProducts As SqlCommand = _ new SqlCommand("SELECT * FROM Products", cnNorthwind) adpProducts.SelectCommand = cmdProducts adpProducts.Fill(ds) cnNorthwind.Close() Console.WriteLine("The connection is closed.") ' You must create a DataRelation to link the two tables. Dim dr As DataRelation Dim dc1 As DataColumn Dim dc2 As DataColumn ' Get the parent and child columns of the two tables. dc1 = ds.Tables("Suppliers").Columns("SupplierID") dc2 = ds.Tables("Products").Columns("SupplierID") dr = new System.Data.DataRelation("suppliers2products", dc1, dc2) ds.Relations.Add(dr) End Sub End Class [C#] using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms;
public class DataGridSample:Form{ DataSet ds; DataGrid myGrid;
static void Main(){ Application.Run(new DataGridSample()); }
public DataGridSample(){ InitializeComponent(); }
void InitializeComponent(){ this.ClientSize = new System.Drawing.Size(550, 450); myGrid = new DataGrid(); myGrid.Location = new Point (10,10); myGrid.Size = new Size(500, 400); myGrid.CaptionText = "Microsoft .NET DataGrid"; this.Text = "C# Grid Example"; this.Controls.Add(myGrid); ConnectToData(); myGrid.SetDataBinding(ds, "Suppliers"); } void ConnectToData(){ // Create the ConnectionString and create a SqlConnection. // Change the data source value to the name of your computer.
string cString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"; SqlConnection myConnection = new SqlConnection(cString); // Create a SqlDataAdapter. SqlDataAdapter myAdapter = new SqlDataAdapter(); myAdapter.TableMappings.Add("Table", "Suppliers"); myConnection.Open(); SqlCommand myCommand = new SqlCommand("SELECT * FROM Suppliers", myConnection); myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand; Console.WriteLine("The connection is open"); ds = new DataSet("Customers"); myAdapter.Fill(ds); // Create a second Adapter and Command. SqlDataAdapter adpProducts = new SqlDataAdapter(); adpProducts.TableMappings.Add("Table", "Products"); SqlCommand cmdProducts = new SqlCommand("SELECT * FROM Products", myConnection); adpProducts.SelectCommand = cmdProducts; adpProducts.Fill(ds); myConnection.Close(); Console.WriteLine("The connection is closed."); System.Data.DataRelation dr; System.Data.DataColumn dc1; System.Data.DataColumn dc2; // Get the parent and child columns of the two tables. dc1 = ds.Tables["Suppliers"].Columns["SupplierID"]; dc2 = ds.Tables["Products"].Columns["SupplierID"]; dr = new System.Data.DataRelation("suppliers2products", dc1, dc2); ds.Relations.Add(dr); } }
-- Vince
"XIAZHIGANG" wrote in message news:552BE6C6-A6DE-4513-B3E7-23E2652BBEDC@microsoft.com... > 我如何才能得到DataSet中表的某一行某一列的值啊?
|
|
|