📄 updatedataset.aspx
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
void Page_Load(Object sender , EventArgs e)
{
DataSet dstPubs;
SqlConnection conPubs;
SqlDataAdapter dadTitles;
DataTable dtblTitles;
DataRow drowTitle;
SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder();
// Grab Titles Table
dstPubs = new DataSet();
conPubs = new SqlConnection( @"Server=localhost;Database=Pubs;Integrated Security=SSPI" );
dadTitles = new SqlDataAdapter( "Select * from Titles", conPubs );
dadTitles.Fill( dstPubs, "Titles" );
dtblTitles = dstPubs.Tables[ "Titles" ];
// Display Original Titles Table
dgrdOriginalTitles.DataSource = dstPubs;
dgrdOriginalTitles.DataBind();
// Add a Row
drowTitle = dtblTitles.NewRow();
drowTitle[ "Title_id" ] = "xxxx";
drowTitle[ "Title" ] = "ASP.NET Unleashed";
drowTitle[ "Price" ] = 1200.00;
drowTitle[ "Type" ] = "Mystery";
drowTitle[ "PubDate" ] = System.DateTime.Now;
dtblTitles.Rows.Add( drowTitle );
// Delete the First Row
//dtblTitles.Rows( 0 ).Delete();
// double the price of the Second Row
//drowTitle = dtblTitles.Rows( 2 );
drowTitle[ "Price" ] = 2;
// Generate the SQL Commands
objCommandBuilder = new SqlCommandBuilder( dadTitles );
// Update Titles Table
//dadTitles.Update( dstPubs, "Titles" );
// Display new Titles Table
dgrdNewTitles.DataSource = dstPubs;
dgrdNewTitles.DataBind();
}
</Script>
<html>
<head><title>UpdateDataSet</title></head>
<body>
<h2>Original Titles Table</h2>
<asp:DataGrid
id="dgrdOriginalTitles"
Runat="Server" />
<h2>New Titles Table</h2>
<asp:DataGrid
id="dgrdNewTitles"
Runat="Server" />
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -