HOW TO: ????? ?????????? DataSet ???? ???????? Visual C# .NET

?????? ????????? ?????? ?????????
???? ???????: 320714 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ?????? ????? ????? ???? DataSet ?????????? ?? ????? ??? ????. ????? ????? DataSet ???? ??? ?? ??? DataSet ????? first-class ????? DataTablesDataSet ?????? ? DataColumns ? ?????? ?????? ?? ??????? ???? ???? ?? ??????? ????? ????.

???????

??????? ??????? ??? ??????? ?????? ??? ? ?????? ? ?????? ???????? ?????? ? ???????? ? ????? ? ??? ?????? ???? ??? ???? ????? ??????? ???????:
  • Microsoft SQL Server 6.5 (?? ????) ?? ????? ?????? Northwind
??????? ???????? ????????:
  • ?????? ?????? ?? Microsoft SQL Server
  • ?????? ?????? ?? Microsoft Visual Studio .NET
  • ?????? ?????? ?? Microsoft ADO.NET
  • ?????? ?????? ?? "????? ???" Microsoft .NET

????? DataSet ????????

???? ??????? ??????? ?????? ????? ??? ???? ???????? Visual Studio .NET. ?????? ????? ??? ?????? DataSet ???? ????? ??????? SQL improvised ?? ????? ?????? Northwind.
  1. ??? ????? Visual Studio .NET.
  2. ????? ????? "????? ???" ???? ???? TDS ?? Visual C# .NET.
  3. ???? ?? ??? "?????? ??????". ??? ?? ??? ??? "?????? ??????" ???? CTRL + ALT + L.
  4. ???? ?? ?? ????? WebForm1.aspx ?????? ?? ???? ????. ??? ?? ??? ????? ???????? ???? ????? ??????? ??? WebForm1.aspx ?? "?????? ??????" ???? ?????.
  5. ??? ???? "????" ? ???? ??? ????? ??????? ??? ????? ????? "?????".
  6. ???? "???? ???????" ? ???? CTRL + ALT + X. ?? ???? ???????? ???? ??? ????? ???. ??? ????? ??????? ??? ????? ?????? ?????? ?? ??????: ????? ?????? ?? ????? ??????? ???? ?? (??? ??? ???? ?? ?????). ??? ??? ? ?? ?????? DataGrid ???? ???????.
  7. ???? ??? ????? ??????. ???? F4 ???? ?????? "?????". ????? ??????? Text ??? ??????. ???? ??? ????? ???? ?? ?? ?????? ??????? Text ??? ?????.
  8. ?????? ???? DataSet ??? ??????? ???? CTRL + SHIFT + A ?? ???? ??? DataSet ?? ????? ?????. ??? DataSet ???????: dsProducts.xsd. ???? ?? ????? ????? ?????? ???? XML. ???? ??? ?????. ???? ???? ???? ???? ?? ???? ???? ????.
  9. ?????? ????? DataSet ???? CTRL + ALT + S ???? "?????? ??????".
  10. ???? ??? ??????? ???? ??? computer name, ???? ??? SQLServers ? ???? ??? server name, ???? ??? Northwind ? ?? ???? ??? ??? ?????.
  11. ??? ????? ????? "Northwind SQL Server" ????? ???????? ??????? ??????? ??? ?? ???? ????? ????? ??? ?????? DataSet ???? ????. ???? ????? ???? ?? ?????? ??????? ???? ??? ??????? ?????? ????? ????? ??? ??????. ??????? XML ?????? ???? ?????? ???? ??? ???? XML ??? ???? ????.
  12. ???? ???? ???????? ??? ???? SQL Server ????. ??? ????? ?????? ????? DataSet ????? ???? ????? ??? ?????? ??? ??????. ???? ??? ?????? ?????? ??? ????? ????? "?????" ????? ?? ????? ?????? ????? DataSet. ??? ?? ??? ??????? ???????. ???? CTRL + S ???? ?????? ?? ????? ?????.
  13. ???? ????? DataSet ????? ??????? ???? ??? ????? ???? ??????? ?? "?????? ??????".
  14. ?? ?????? ???? ????? dsProducts.xsd. ???? ??? dsProducts.vb ????? ????? ??? ????? ??? ??????. ???? ????? ??? dsProducts.xsx ??? ??????? ???? ????????? ??? ???????.
  15. ?????? ??????? ?????? ???? ????? DataSet ???? ????? ??????? ??? ?????? ??? "????? ???" (???? ??? ???? ???? ???). ???? "????? ???" codebehind ????? ???? ??????? ???? ????? Page_Load.
  16. ?????? ?????? ???????? ?? ????? ????? System.Data.SqlClient ????? ??????? ???????? ??????? ?? ???? codebehind:
    using System.Data.SqlClient;
    					
    ??????: ?????? ???? ????? ??? ?????? ?????? ??? ??? ???? ??? ?????? ???????? ????? ?? ??????? ??? ????? ????? ??? ?? Visual Studio .NET.

  17. ?? ????? ????? Page_Load ????? ???? ????? ?????? ????? ????? ??????? ??? ????? ??????? ????? SqlConnection:
    SqlConnection cn = new SqlConnection("server=myserver;uid=myuid;pwd=mypassword;database=northwind");
    					
  18. ????? ???? SqlCommand ?? ??? ?????? ??? ???? SqlDataAdapter. ????? ????? SQL improvised ? ???? ????? ???? ??? ????? SqlCommand. ????? ???? ?????? ????? CommandText ???? SqlCommand ????. ????? ????? ????? ??? ????? ????.
    SqlCommand cmd = new SqlCommand("select * from [Alphabetical list of products]", cn);
    					
  19. ????? ???? ?? ?????? SqlDataAdapter ????? ???? SqlCommand ?????? ?????:
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    					
  20. ???? ????? ???????? ???????? ??????? ?????? ???????? ???????. ?????? ?? ??? ????? DataSet. ???? ??? ??? ????? ???? ???? dsProducts: ????? ???? ?????? dsProducts ???? ???? ?? ??? DataSet ??? ??? DataSet ????? ?????.
    dsProducts tds = new dsProducts();
    					
  21. ??????? ??????? ??????? ?? SqlDataAdapter ????? ?? ?????? DataSet ????? ???? ?????? DataSet ?????? ??????? DataTable TableName:
    da.Fill(tds, tds.Tables[0].TableName);
    					
  22. ?????? ????? ???? ???? ??????? Text ???? ??? ????? ????? ???? ?? ????? DataSet ?????? DataTable ?????? ??????? ??????:
    dsProducts.DataTableName[RowIndex].ColumnName
    						
    ?? ??? ??????? ????? RowIndex ??? ????? - ?????? ??? 5:
    TextBox1.Text = tds.Alphabetical_list_of_products[5].ProductName;
    TextBox2.Text = tds.Alphabetical_list_of_products[5].CategoryName; 
    						
    ??? ?????? ???? ????? ? ??? ????? ?????? ???? ?? ????? ???? ?????? ?? ???? ????? ?????? ????????? ?????? ?? ???? ?????? DataGrid.
  23. ???? ???? ??????? ?? DataGrid ????? ??????? DataSource DataGrid ??? ???? ???? DataSet ???????? DataBind():
    DataGrid1.DataSource = tds;
    DataGrid1.DataBind();
    					

????? ??? ????? (WebForm1.aspx)

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TDS.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
	<title>WebForm1</title>
	<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
	<meta name="CODE_LANGUAGE" Content="C#">
	<meta name="vs_defaultClientScript" content="JavaScript">
	<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
	<form id="Form1" method="post" runat="server">
		<asp:Label id="Label1"  runat="server" >Label</asp:Label>
		<asp:DataGrid id="DataGrid1"  runat="server" ></asp:DataGrid>
		<asp:TextBox id="TextBox2"  runat="server"></asp:TextBox>
		<asp:TextBox id="TextBox1"  runat="server"></asp:TextBox>
		<asp:Label id="Label2"  runat="server" >Label</asp:Label>
	</form>
</body>
</HTML>
				

????? ??? ????? (WebForm1.aspx.cs)

using System.Data.SqlClient;

namespace TDS
{
  /// <summary>
  /// Summary description for WebForm1.
  /// </summary>
  public class WebForm1 : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
    private void Page_Load(object sender, System.EventArgs e) 
    {
	SqlConnection cn = new SqlConnection("server=localhost;uid=sa;pwd=abcd;database=northwind");
	SqlCommand cmd = new SqlCommand("select * from [Alphabetical list of products]", cn);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	dsProducts tds = new dsProducts();

	da.Fill(tds, tds.Tables[0].TableName);
	TextBox1.Text = tds.Alphabetical_list_of_products[5].ProductName;
	TextBox2.Text = tds.Alphabetical_list_of_products[5].CategoryName; 

         DataGrid1.DataSource = tds;
	DataGrid1.DataBind();

    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
	// 
	// CODEGEN: This call is required by the ASP.NET Web Form Designer.
	// 
	InitializeComponent();
	base.OnInit(e);
    }
		
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
	this.TextBox1.TextChanged += new System.EventHandler(this.TextBox1_TextChanged);
	this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
  }
}

				

??????

???? F5 ?????? ????? ???. ???? ???????? "Uncle ???? ???? Dried ?????" ?? ???? ???? ?????? ? "?????" ?? ???? ?? ?????. ???? DataGrid ????? ?? ??????? ?????? ??? ?????? ????.

??????? ??????? ????????

  • ?? ????? ??? ????? DataSet ????? TableName ??? ??????? ??????? ???????. ????? ????? DataSet ??? ???? ????? ???, ??? ??? ??? ?????? ??? ?????? ????DataSet ?????? ?????? ????? ????? ?? TableName. ???? ??? ?????? ????? DataSet ?????? TableName ??? "???? ?? ?? ?? ?????? 0" ?? ??? ???????. ??? ??????? ????? ????? DataSet ????? ??? ?? ??? ???? ???? ?? ???? ?????? ?? TableName ???? ???? ??? ??????? ???? ?? ??? DataSet ????? ???? ??? ?????? ???? ??? ?? ????????? ???????? ??????.
  • ??? ??????? ??? ??? ??????? ????? ???? ???????? ??? ?????? ???? ?? ?????? ?????? Visual Studio .NET ??? ??? ?????? ???? ????? ?????? ?? ????? ??????? ????? ?????? ?????? ?? ????? ??? DataSet ??? ????? ??? ???? ??? ????? ????? "?????" "??????". ???? ???? ???? ??? ?????? ??????? ???? ??? ????? Microsoft SQL Server ? ?????? ????? ????? DataSet ?? ?????? ?????? ???? ???????.

?????

????? ?? ????????? ??? ????? ?? ????? DataSet ???? ???? Microsoft ?????? ??? ?????:
http://msdn2.microsoft.com/en-us/library/esbykkzb(vs.71).aspx


???????

???? ???????: 320714 - ????? ??? ??????: 30/???? ??????/1428 - ??????: 2.3
????? ???
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET 1.1
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
????? ??????: 
kbmt kbhowtomaster KB320714 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????320714

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com