Asp.net Method for updating a specified record, asp.net specifies a record

Source: Internet
Author: User

Asp.net Method for updating a specified record, asp.net specifies a record

This example describes how to update a specified record in asp.net. Share it with you for your reference. The specific method is as follows:

Let's first look at the html page:
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<Form id = "form1" runat = "server">

<Div style = "text-align: center">
<Table style = "width: 302px; height: 246px;">
<Tr>
<Td colspan = "2" style = "width: 496px">
<Asp: label ID = "Label2" runat = "server" Text = "Update specified data" Font-Bold = "True" ForeColor = "Blue" Width = "132px"> </asp: label> </td>
</Tr>
<Tr>
<Td colspan = "2" style = "width: 496px">
<Asp: gridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False" CellPadding = "4" Font-Size = "Smaller" ForeColor = "#333333" GridLines = "None">
<Columns>
<Asp: BoundField DataField = "Product NO." HeaderText = "Product NO."/>
<Asp: BoundField DataField = "Product Name" HeaderText = "Product Name"/>
<Asp: BoundField DataField = "item quantity" HeaderText = "item quantity"/>
<Asp: BoundField DataField = "product price" HeaderText = "product price"/>
<Asp: HyperLinkField DataNavigateUrlFields = "Product NO." DataNavigateUrlFormatString = "Default. aspx? Item No. = {0 }"
HeaderText = "Update" Text = "Update"/>
</Columns>
<FooterStyle BackColor = "# 5D7B9D" Font-Bold = "True" ForeColor = "White"/>
<RowStyle BackColor = "# F7F6F3" ForeColor = "#333333"/>
<EditRowStyle BackColor = "#999999" type = "regxph" text = "yourobjectname"/>
<SelectedRowStyle BackColor = "# E2DED6" Font-Bold = "True" ForeColor = "#333333"/>
<PagerStyle BackColor = "#284775" ForeColor = "White" HorizontalAlign = "Center"/>
<HeaderStyle BackColor = "# 5D7B9D" Font-Bold = "True" ForeColor = "White"/>
<AlternatingRowStyle BackColor = "White" ForeColor = "#284775"/>
</Asp: GridView>
</Td>
</Tr>
<Tr>
<Td colspan = "2" style = "width: 496px" align = "center">
</Td>
</Tr>
<Tr>
<Td colspan = "2" style = "width: 496px">
<Asp: Label ID = "Label3" runat = "server" Font-Size = "Smaller" Text = "Product Name:" Width = "65px"> </asp: label> <asp: TextBox ID = "TxtName" runat = "server"> </asp: TextBox>
</Td>
</Tr>
<Tr>
<Td colspan = "2">
<Asp: Label ID = "Label4" runat = "server" Font-Size = "Smaller" Text = "item quantity:"> </asp: Label>
<Asp: TextBox ID = "TxtNum" runat = "server"> </asp: TextBox> </td>
</Tr>
<Tr>
<Td colspan = "2">
<Asp: Label ID = "Label5" runat = "server" Font-Size = "Smaller" Text = "product price:"> </asp: Label>
<Asp: TextBox ID = "TxtPrice" runat = "server"> </asp: TextBox> </td>
</Tr>
<Tr>
<Td colspan = "2" style = "width: 496px">
<Asp: Button ID = "BtnUpdate" runat = "server" OnClick = "BtnUpdate_Click" Text = "Update" Width = "55px"/> </td>
</Tr>
</Table>
</Div>
</Form>
The data submitted on the preceding page is accepted and then updated using SQL.
Copy codeThe Code is as follows: View Code
Using System;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Data. SqlClient;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack) // when the Page is executed for the first time
{
GridViewBind (); // bind the custom method GridViewBind
If (Request. QueryString ["item No."]! = Null) // judge. If you can obtain the id value, perform the following operations:
{
SqlConnection con = new SqlConnection (ConfigurationSettings. deleettings ["strCon"]);
Con. Open ();
SqlDataAdapter ada = new SqlDataAdapter ("select * from tb_shopping05 where item No. =" + Request. QueryString ["item No."] + "", con );
DataSet ds = new DataSet ();
Ada. Fill (ds, "tb_shopping05 ");
DataRowView drv = ds. Tables ["tb_shopping05"]. DefaultView [0];
This. TxtName. Text = drv ["Product Name"]. ToString ();
This. TxtNum. Text = drv ["item quantity"]. ToString ();
This. TxtPrice. Text = drv ["product unit price"]. ToString ();
}
}
}
Public void GridViewBind () // custom method for binding the GridView Control
{
SqlConnection con = new SqlConnection (ConfigurationSettings. deleettings ["strCon"]);
Con. Open ();
SqlDataAdapter ada = new SqlDataAdapter ("select * from tb_shopping05", con );
DataSet ds = new DataSet ();
Ada. Fill (ds );
GridView1.DataSource = ds;
GridView1.DataBind ();
Con. Close ();
}
Protected void BtnUpdate_Click (object sender, EventArgs e)
{
Try
{
SqlConnection con = new SqlConnection (ConfigurationSettings. deleettings ["strCon"]);
Con. Open ();
SqlCommand com = new SqlCommand ("update tb_shopping05 set item name = '" + this. txtName. text + "', item quantity ='" + this. txtNum. text + "', product unit price ='" + this. txtPrice. text + "'where product no. =" + Request ["Product NO."], con );
Com. ExecuteNonQuery ();
GridViewBind ();
Response. Write ("<script language = javascript> alert ('Congratulations! Information updated! ') </Script> ");
}
Catch
{
Response. Write ("<script language = javascript> alert ('sorry! An error occurred while updating the information! ') </Script> ");
}
}
}
The principle is that, when we click on the edited data, an ID will be sent, and then we can use SQL to update the accepted data.

I hope this article will help you design your asp.net program.


How to display records of a specified date in aspnet

(1)
The Calendar control has a SelectedDate attribute that shows the selected date. The type is datetime.
Example: string time = Calendar1.SelectedDate. ToString ();

Then query the database based on time

Select * from visited where sdate like '% time %'

(2)
I don't know what timer you are referring to. The SQL statement is datediff, which can be used to count the data of a time.

What is the difference between a record set and a dataset in asp and aspnet? How to locate a record in a record set or dataset?

The Microsoft. NET Framework is a platform for generating, deploying, and running Web services and applications. It provides a highly productive and standard-based multilingual environment for integrating existing investments with next-generation applications and services, it also provides flexibility to solve the deployment and operation difficulties of Internet-scale applications .. The NET framework consists of three main parts: the public Language Runtime Library, the hierarchical set of unified class libraries, and the Active Server Pages componentized version called ASP. NET. In the. NET architecture, XML is the key to seamless connection between applications. There are various arguments about. NET. But at that time, Ballmer, CEO, should be the most representative of Microsoft's view. He said: "Microsoft. NET represents a set, an environment, and a programmable structure that can be used as a platform to support the next-generation Internet." Indeed, this statement briefly describes the external features of. NET.. NET is an environment first. This is an idealized future Internet environment. Microsoft's vision is an Internet environment that no longer focuses on a single website, a single device, and an Internet environment connected to the Internet, instead, all computer groups, related devices, and service providers must work together in a network computing environment. In short, the services provided by the Internet must be able to perform more automatic processing. In the future, the Internet should be presented to end users as a whole service. Users only need to know what they want, you do not need to search and operate on the Internet step by step to achieve your goal. This is an ideal, but it is indeed the development trend of the Internet.. NET seeks an ideal Internet environment. To build such an Internet environment, the first problem to be solved is to design and create a next-generation Internet structure based on the gaps in the existing Internet. This structure is not a topological structure on the physical network layer, but a programmable Internet software structure that is different from the browser's static browsing. Therefore,. NET positions itself as a programmable structure that supports the next-generation Internet. The ultimate goal of. NET is to allow users to access the information, files, and programs they need anywhere, anytime, and using any device. Users do not need to know where these things exist, or even how to obtain details. They only need to send a request and then simply receive the request. The complexity of all backend services is completely shielded. Therefore, for enterprise IT staff, they do not need to manage complicated platforms and coordinate the work between various distributed applications.. NET Framework includes the general language runtime environment, Framework class library, and Active Server Pages +. It has an ideal goal and a programmable Internet software structure ,. the specific implementation of a collaborative computing environment such as NET also requires a series of software product support, so Microsoft's. NET also includes a collection of products. This set includes the following components :. the NET platform is based on XML and internet standard protocols, including. NET infrastructure and basic tools provide an advanced architecture model for the development of new interactive collaboration software.. NET products and services such as MSN. NET, OFFICE. NET, Visual Studio. NET, and bCentral. NET. Third-party vendor. NET services are built on the. NET platform and products for specific services in different application fields. From the simple analysis of. NET, we can see that Microsoft is still indispensable in promoting new technologies and the IT industry. But at the same time, it can be inferred that if. NET becomes a fact, it may cause great competition pressure for other non-application software vendors.. NET technical features. NET includes four important features: software change service, XML-based common language, integration of multiple devices and platforms, and a new generation of man-machine interface. These four features basically cover the technical features of. NET. Software change service Steve Ballmer talked about software services... the remaining full text>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.