添加单条数据
来源:互联网 发布:开淘宝店注册公司 编辑:程序博客网 时间:2024/05/18 04:56
Default.aspx
View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>添加单条数据实例</title></head><body background="image/background.gif"> <form id="form1" runat="server"> <div> <div style="text-align: center"> <br /> <br /> <table style="width: 668px; height: 230px; background-image: url(image/background1.gif);"> <tr> <td colspan="4" style="height: 133px"> <asp:Image ID="Image2" runat="server" ImageUrl="~/image/head.gif" /></td> </tr> <tr> <td style="width: 100px; height: 47px;"> </td> <td style="width: 100px; background-image: url(image/background1.gif); height: 48px;" colspan="2" align="center"> <asp:Image ID="Image3" runat="server" ImageUrl="~/image/mail.gif" /></td> <td style="width: 100px; height: 47px;"> </td> </tr> <tr> <td style="width: 100px; height: 19px;"> </td> <td style="width: 100px; background-image: url(image/background1.gif); height: 48px;" align="center"> <asp:Image ID="Image4" runat="server" ImageUrl="~/image/Address.gif" /></td> <td style="width: 100px; background-image: url(image/background1.gif); height: 48px;"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> <td style="width: 100px; height: 19px;"> </td> </tr> <tr> <td style="width: 100px; height: 48px"> </td> <td style="background-image: url(image/background1.gif); width: 100px; height: 48px" align="center"> <asp:Image ID="Image5" runat="server" ImageUrl="~/image/title.gif" /></td> <td style="background-image: url(image/background1.gif); width: 100px; height: 48px" align="left"> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td> <td style="width: 100px; height: 48px"> </td> </tr> <tr> <td style="width: 100px; height: 34px"> </td> <td style="background-image: url(image/background1.gif); width: 100px; height: 34px"> <asp:Image ID="Image6" runat="server" ImageUrl="~/image/neirong.gif" /></td> <td style="background-image: url(image/background1.gif); width: 100px; height: 34px" align="left"> <asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Height="72px" Width="147px"></asp:TextBox></td> <td style="width: 100px; height: 34px"> </td> </tr> <tr> <td style="width: 100px; height: 48px"> </td> <td style="background-image: url(image/background1.gif); height: 48px" colspan="2" align="center"> <asp:ImageButton ID="ImgBtnSend" runat="server" ImageUrl="~/image/send.gif" OnClick="ImgBtnSend_Click" /> <asp:ImageButton ID="ImgBtnCZ" runat="server" ImageUrl="~/image/CZ.gif" /></td> <td style="width: 100px; height: 48px"> </td> </tr> <tr> <td style="width: 100px"> </td> <td style="background-image: url(image/background1.gif); height: 48px;" colspan="2"> <asp:Image ID="Image7" runat="server" ImageUrl="~/image/notice.gif" /></td> <td style="width: 100px"> </td> </tr> <tr> <td colspan="4"> <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" Font-Size="Smaller" ForeColor="Black" GridLines="Vertical" Width="720px" AllowPaging="True" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="3"> <FooterStyle BackColor="#CCCC99" /> <RowStyle BackColor="#F7F7DE" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="收件人地址" HeaderText="收件人地址" /> <asp:BoundField DataField="标题" HeaderText="标题" /> <asp:BoundField DataField="内容" HeaderText="内容" /> </Columns> </asp:GridView> </td> </tr> <tr> <td colspan="4"> <asp:Image ID="Image1" runat="server" ImageUrl="~/image/foot.gif" /></td> </tr> </table> </div> </div> </form></body></html>
Default.aspx.cs
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) { this.bindGridview();//调用自定义方法绑定控件数据 } } public void bindGridview() { SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]); con.Open();//打开数据库连接 SqlDataAdapter ada = new SqlDataAdapter("Select * From tb_Send05", con);//创建数据适配器 DataSet ds = new DataSet();//创建数据集 ada.Fill(ds);//填充数据集 GridView1.DataSource = ds;//绑定数据 GridView1.DataBind(); con.Close(); } protected void ImgBtnSend_Click(object sender, ImageClickEventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]); con.Open(); string InsertSql = "Insert Into tb_send05 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')"; SqlCommand com = new SqlCommand(InsertSql, con);//创建执行SQL命令的SqlCommand对象 com.ExecuteNonQuery();//执行添加操作 SqlDataAdapter ada = new SqlDataAdapter("Select * From tb_Send05", con);//创建适配器 DataSet ds = new DataSet(); ada.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); Response.Write("<script language=javascript>alert('添加成功!')</script>"); } catch { Response.Write("<script language=javascript>alert('添加失败!')</script>"); } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.GridView1.PageIndex = e.NewPageIndex; this.bindGridview(); }}
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 添加单条数据
- 插入单条数据
- MyBatis插入单条数据
- LitJson删除单条数据
- jquery easyui griddata 得到单条数据、。
- 读取单条json数据代码
- 取每个组中的单条数据
- DML语句---插入单条数据记录
- 超级表格如何单条共享数据
- MyBatis(四) 删除单条数据
- 触发器---单条与多条数据日志的考虑
- mysql 单条insert语句,插入多条数据记录
- PLSQL批量插入单条、多条数据过程
- java 依次单条数据 写入数据库 500万条
- MySQL 单条语句 插入多条数据
- SQL Server数据库添加100条数据
- Oracle中同时添加多条数据
- 数据库新增向父表插入单条数据向子表插入多条数据
- PS的aux和-ef参数
- 在linux上运行source insight
- Duck Duck Go Architecture
- 第四周项目二 三角形类
- Outlook2010到处通讯录
- 添加单条数据
- php启动外部某个可执行的exe文件,exe文件为界面执行文件。
- oracle优化避免全表扫描
- Gmail导入通讯录
- WCF基本资料
- String类及正则表达式
- CSS:IE,Chrome,Firefox兼容性和CSS Hack
- 负载大逃亡:四十二路怪兽联军及七条逃生法则(很喜欢)
- 关于PHP自定义扩展加载的问题