![嵌入式SQL數(shù)據(jù)編輯實(shí)驗(yàn)3_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/4b761064-2862-42d8-a4a3-f5df23bd8b2e/4b761064-2862-42d8-a4a3-f5df23bd8b2e1.gif)
![嵌入式SQL數(shù)據(jù)編輯實(shí)驗(yàn)3_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/4b761064-2862-42d8-a4a3-f5df23bd8b2e/4b761064-2862-42d8-a4a3-f5df23bd8b2e2.gif)
![嵌入式SQL數(shù)據(jù)編輯實(shí)驗(yàn)3_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/4b761064-2862-42d8-a4a3-f5df23bd8b2e/4b761064-2862-42d8-a4a3-f5df23bd8b2e3.gif)
![嵌入式SQL數(shù)據(jù)編輯實(shí)驗(yàn)3_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/4b761064-2862-42d8-a4a3-f5df23bd8b2e/4b761064-2862-42d8-a4a3-f5df23bd8b2e4.gif)
![嵌入式SQL數(shù)據(jù)編輯實(shí)驗(yàn)3_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/11/4b761064-2862-42d8-a4a3-f5df23bd8b2e/4b761064-2862-42d8-a4a3-f5df23bd8b2e5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、實(shí)驗(yàn)三 嵌入式SQL數(shù)據(jù)編輯一、實(shí)驗(yàn)?zāi)康模?)了解嵌入式SQL的使用方法。(2)設(shè)計(jì)用戶界面,能對數(shù)據(jù)表進(jìn)行添加、刪除。二、實(shí)驗(yàn)內(nèi)容設(shè)計(jì)一個(gè)應(yīng)用程序,實(shí)現(xiàn)對教學(xué)管理數(shù)據(jù)庫中所選定的表進(jìn)行添加刪除。用戶界面如圖1所示。圖1 用戶界面完成以下功能:(1)在學(xué)號、姓名、性別、年齡等輸入框中輸入一個(gè)值,點(diǎn)擊添加按鈕,能夠添加相應(yīng)記錄。點(diǎn)擊相應(yīng)記錄的刪除按鈕,能夠刪除記錄。三、實(shí)驗(yàn)指導(dǎo)(一)C# 嵌入式SQL語句1.在SQL Server中建立訪問數(shù)據(jù)庫的用戶stm;2. 在web.config中增加配置項(xiàng):<connectionStrings><add name="conn
2、" connectionString="Data Source=;Initial Catalog=stm;User ID=stm;Password=" providerName=""/></connectionStrings>3繪制程序界面,如圖1所示,使用表格進(jìn)行布局。(1) 添加數(shù)據(jù)源;(2) 編輯GradView,增加數(shù)據(jù)綁定列;(3) 編輯GradView,增加模板列,在模板列中添加“刪除”按鈕。4. 建立連接并執(zhí)行SQL命令string strconn = ConfigurationManager.
3、ConnectionStrings"conn".ConnectionString; SqlConnection con = new SqlConnection(strconn); con.Open();SqlCommand cm = new SqlCommand(sql, con); cm.ExecuteNonQuery(); con.Close();其中,sql是訪問數(shù)據(jù)庫的SQL語句,通過用戶填寫情況合成。實(shí) 驗(yàn) 報(bào) 告實(shí)驗(yàn)三 嵌入式SQL數(shù)據(jù)編輯裁剪線學(xué) 號: 姓名: 成績: 學(xué)院(系): 專業(yè): 班級: 一、實(shí)驗(yàn)?zāi)康模?)了解嵌入式SQL的使用方法。(2)設(shè)計(jì)用戶界
4、面,能對數(shù)據(jù)表進(jìn)行添加刪除。二、實(shí)驗(yàn)內(nèi)容1設(shè)計(jì)一個(gè)客戶端數(shù)據(jù)編輯程序三、問題和要求1寫出程序運(yùn)行主要界面2寫出主要事件及代碼<% Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR
5、/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head id="Head1" runat="server"> <title>無標(biāo)題頁</title> <style type="text/css"> #form1 height: 42px; width: 573px; </style></head><
6、body> <form id="form1" runat="server"> <table> <tr> <td> <asp:Label ID="學(xué)號Label1" runat="server" Text="學(xué)號:"></asp:Label> <asp:TextBox ID="學(xué)號TextBox0" runat="server"></asp:TextBox>
7、 </td> <td> <asp:Label ID="姓名Label1" runat="server" Text="姓名:"></asp:Label> <asp:TextBox ID="姓名TextBox0" runat="server"></asp:TextBox> </td> <td> <asp:Label ID="性別Label1" runat="server
8、" Text="性別:"></asp:Label> <asp:DropDownList ID="性別DropDownList1" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem>男</asp:ListItem> <asp:ListItem>女</asp:ListItem> </asp:DropDownList> </td> <
9、;/tr> <tr> <td> <asp:Label ID="年齡從Label1" runat="server" Text="年齡:"></asp:Label> <asp:TextBox ID="年齡TextBox0" runat="server"></asp:TextBox> </td> <td> </td> <td align="right&q
10、uot;> <asp:Button ID="添加Button1" runat="server" Text="添加" onclick="添加Button1_Click" Width="55px" /> </td> </tr> </table> <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor
11、="#333333" GridLines="None" Width="455px" onrowdeleting="GridView1_RowDeleting"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333&qu
12、ot; /> <Columns> <asp:CommandField ShowDeleteButton="True" /> </Columns> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" Fo
13、reColor="Navy" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> </form></body></html>using System;using System.Configuration;usi
14、ng System.Data;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.Data.SqlClient; /需要添加命令空間public partial class _Default : System.Web.UI.Page protected void Page_Load(ob
15、ject sender, EventArgs e) sql_sel(); protected void 添加Button1_Click(object sender, EventArgs e) string xuehao = 學(xué)號TextBox0.Text; string xingming = 姓名TextBox0.Text; string xingbie = 性別DropDownList1.Text; string nianling = 年齡TextBox0.Text; string sql = "insert into s values('" + xuehao +
16、 "','" + xingming + "'," + Convert.ToInt32(nianling) + ",'" + xingbie + "')" sql_deal(sql); sql_sel(); void sql_sel() string strconn = ConfigurationManager.ConnectionStrings"conn".ConnectionString; /調(diào)用web.config中的conn 返回連接字符串 SqlC
17、onnection con = new SqlConnection(strconn); /進(jìn)行連接 con.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from s", con); /執(zhí)行sql語句,返回?cái)?shù)據(jù) DataSet ds = new DataSet(); da.Fill(ds); /添加到數(shù)據(jù)集中 GridView1.DataSource = ds; /進(jìn)行數(shù)據(jù)綁定 GridView1.DataBind(); con.Close(); /關(guān)閉數(shù)據(jù)庫連接 void sql_deal(string sql) string strconn = ConfigurationManager.ConnectionStrings"conn".ConnectionString; SqlConnection con = new SqlConnection(strconn); con.Open(); SqlCommand cm = new SqlCommand(sql,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 12古詩三首《示兒》說課稿-2024-2025學(xué)年五年級語文上冊統(tǒng)編版001
- 2023六年級數(shù)學(xué)上冊 四 人體的奧秘-比說課稿 青島版六三制
- 會(huì)議總包合同范例
- 鋼板橋面面層施工方案
- 供熱公司用工合同范本
- 專業(yè)律師合同范例
- 債務(wù)合約合同范例
- 物業(yè)車輛清潔方案
- 公司聘用文秘合同范例
- 買礦協(xié)議合同范本
- 第八講 發(fā)展全過程人民民主PPT習(xí)概論2023優(yōu)化版教學(xué)課件
- 王崧舟:學(xué)習(xí)任務(wù)群與課堂教學(xué)變革 2022版新課程標(biāo)準(zhǔn)解讀解析資料 57
- 招投標(biāo)現(xiàn)場項(xiàng)目經(jīng)理答辯(完整版)資料
- 運(yùn)動(dòng)競賽學(xué)課件
- 重大事故隱患整改臺賬
- 2022年上海市初中畢業(yè)數(shù)學(xué)課程終結(jié)性評價(jià)指南
- 高考作文備考-議論文對比論證 課件14張
- 新華師大版七年級下冊初中數(shù)學(xué) 7.4 實(shí)踐與探索課時(shí)練(課后作業(yè)設(shè)計(jì))
- 山東省萊陽市望嵐口礦區(qū)頁巖礦
- 《普通生物學(xué)教案》word版
- 安全生產(chǎn)應(yīng)知應(yīng)會(huì)培訓(xùn)課件
評論
0/150
提交評論