: DataSet, , . DataSet 㳿 ADO.NET , , .
䳿 볺 , ', ' . , , ' . 䳿 , .. ADO.NET 䳿 , 䒺 .
䒺 䳿 , ﳿ 볺, , 볺, , , . , 䒺 , , , . , ' , 䳿 . ' ADO.NET, .
1. . . , ' Connecton. tovar, SQL Server
string connectionString;
connectionString = "Data Source=KATYAN\\SQLEXPRESS;Initial Catalog=tovar;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
string sql="select * from tovar";
' DataAdapter , .
SqlDataAdapter sa = new SqlDataAdapter(sql, con);
' DataSet DataAdapter.
DataSet ds = new DataSet();
sa.Fill(ds, "tovar");
' Label . GetProductName(), tovar.
public string GetProductName()
{return ds.Tables["tovar"].Rows[0]["nazv"].ToString();}
Label .aspx ' Text .
<asp:Label ID="Label1" runat="server" Text="<%#GetProductName() %>"></asp:Label>
|
|
Page.Load() Page.DataBnd(). . 4.1. using System.Data.SqlClient.
public void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
. 4.1. -
:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default: System.Web.UI.Page
{
DataSet ds = new DataSet();
public void Page_Load(object sender, EventArgs e)
{ string connectionString;
connectionString = "Data Source=KATYAN\\SQLEXPRESS;Initial Catalog=tovar;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
string sql = "select * from tovar";
SqlDataAdapter sa = new SqlDataAdapter(sql, con);
sa.Fill(ds, "tovar");
Page.DataBind();
}
public string GetProductName()
{ return ds.Tables["tovar"].Rows[0]["nazv"].ToString();
}
}
2. . DropDownLst1 LstBox1, ' , tovar.
<asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
䳿 , .
DropDownList1.DataSource = ds.Tables["tovar"];
DropDownList1.DataTextField = "nazv";
DropDownList1.DataValueField = "kod_tov";
ListBox1.DataSource = ds.Tables["tovar"];
ListBox1.DataTextField = "nazv";
ListBox1.DataValueField = "kod_tov";
Page.DataBind();
, . 4.2.
. 4.2.
3. ᒺ GridView . GrdVew. . ' GrdVew DataSource. ' GrdVew, ' tovar . ᒺ GrdVew.
<asp:GridView ID="GridView1" runat="server"> </asp:GridView>
䳿 :
GridView1.DataSource = ds.Tables["tovar"];
this.DataBind();
䳿 . 4.3.
. 4.3. ³ GrdVew
|
|
4. , . tovar , post order . order kod_post kod_tov, post order (. 4.4).
. 4.4.
DropDownLst SqlDataSource. , . . ᒺ SqlDataSource , , SqlDataSource Design ToolBox. , (. 4.5).
. 4.5.
, , . ϳ , . 4.6.
. 4.6.
, . Test Connection. , (. 4.7).
. 4.7.
(. 4.8).
. 4.8.
, (. 4.9).
. 4.9.
Next (. 4.10), , ( , ), .
. 4.10.
Advanced , (. 4.11).
. 4.11.
Next (. 4.12)
. 4.12.
䳿 ᒺ SqlDataSource , . ϳ , web.confg .
<connectionStrings>
<add name="tovarConnectionString" connectionString="Data Source=KATYAN\SQLEXPRESS;Initial Catalog=tovar;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
.aspx :
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:tovarConnectionString %>"
SelectCommand="SELECT Distinct [kod_tov],[nazv],[gost] FROM [tovar]" >
</asp:SqlDataSource>
. (. 4.13).
. 4.13. DropDownLst
Choose Data Source, (. 4.14), . ᒺ SqlDataSource.
|
|
. 4.14. ᒺ SqlDataSource
, , (. 4.15).
. 4.15. DropDownLst
:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID= "SqlDataSource1" DataTextField="nazv" DataValueField="kod_tov" Width="200px" AutoPostBack="true">
</asp:DropDownList>
, AutoPostBack DropDownLst true. . , . (. 4.16).
. 4.16. -
, , GrdVew, . GrdVew SqlDataSource. SqlDataSource . , GrdVew , . ᒺ SqlDataSource :
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString= "<%$ ConnectionStrings:tovarConnectionString %>" SelectCommand="SELECT orders.kod_oper, orders.data, post.nazv AS postav, orders.kol, orders.price, orders.kol * orders.price AS FROM orders INNER JOIN post ON orders.kod_post = post.kod_post WHERE (orders.kod_tov = @product)" >
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="product" PropertyName= "SelectedValue" /> </SelectParameters>
</asp:SqlDataSource>
SqlDataSource , SelectCommand , <SelectParameters>. @roduct, . , ' roduct. SelectedValue ' DropDownLst1. ᒺ SqlDataSource ᒺ GridView. :
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource2"
AutoGenerateColumns="False" DataKeyNames="kod_oper">
<Columns>
<asp:BoundField DataField="kod_oper" HeaderText="kod_oper" InsertVisible= "False" ReadOnly="True" SortExpression="kod_oper" />
<asp:BoundField DataField="data" HeaderText="data" SortExpression="data" />
<asp:BoundField DataField="postav" HeaderText="postav" SortExpression="postav" />
<asp:BoundField DataField="kol" HeaderText="kol" SortExpression="kol" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="" HeaderText="" ReadOnly= "True" SortExpression="" />
|
|
</Columns>
</asp:GridView>
(. 4.17, 4.18), .
. 4.17.
. 4.18. ³