VS2010 采用web方式發(fā)布新聞(上傳到數(shù)據(jù)庫)簡(jiǎn)單版_第1頁
VS2010 采用web方式發(fā)布新聞(上傳到數(shù)據(jù)庫)簡(jiǎn)單版_第2頁
VS2010 采用web方式發(fā)布新聞(上傳到數(shù)據(jù)庫)簡(jiǎn)單版_第3頁
VS2010 采用web方式發(fā)布新聞(上傳到數(shù)據(jù)庫)簡(jiǎn)單版_第4頁
VS2010 采用web方式發(fā)布新聞(上傳到數(shù)據(jù)庫)簡(jiǎn)單版_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí) 驗(yàn) 報(bào) 告專業(yè)13網(wǎng)絡(luò)工程 班級(jí) 1班 學(xué)號(hào)201324132153 姓名 劉煜明 課程名稱 網(wǎng)絡(luò)應(yīng)用程序開發(fā) 學(xué)年2015 -2016 學(xué)期1 / 2 課程類別專業(yè)必修 限選 任選 實(shí)踐 實(shí)驗(yàn)時(shí)間2016年5 月31 日實(shí)驗(yàn)名稱 采用web方式發(fā)布新聞實(shí)驗(yàn)?zāi)康暮鸵?本實(shí)驗(yàn)設(shè)計(jì)是在Visual Studio 2010程序下,采用web方式把新聞信息發(fā)布到數(shù)據(jù)庫中,以便網(wǎng)站引用該新聞內(nèi)容。實(shí)驗(yàn)環(huán)境要求軟件:Microsoft Visual Studio 2010 SQL Server 2008實(shí)驗(yàn)內(nèi)容、方法和步驟(見附頁1)1. 在SQL創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù)表2. 在VS2010新建一個(gè)C#語

2、言的web應(yīng)用程序項(xiàng)目3. 設(shè)計(jì)發(fā)布新聞頁面模板4. 實(shí)現(xiàn)后臺(tái)功能,發(fā)布新聞到數(shù)據(jù)庫中實(shí)驗(yàn)結(jié)果(見附頁2)程序源代碼 (見附頁3)評(píng)定成績(jī): 批閱教師: 年 月 日實(shí) 驗(yàn) 報(bào) 告(附頁1)1. 在SQL創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù)表如下圖所示:2. 在VS2010新建一個(gè)C#語言的web應(yīng)用程序項(xiàng)目如下圖所示,按照實(shí)驗(yàn)要求,新建一個(gè)Newspublish的web項(xiàng)目,然后新建C#的web窗體,名字是NewsPublish:3. 設(shè)計(jì)頁面模板如下圖所示,拖動(dòng)控件按如下的方式擺放:4. 實(shí)現(xiàn)后臺(tái)功能,查詢數(shù)據(jù)庫(1) 使用ConfigurationManager和SqlConnection函數(shù)連接數(shù)據(jù)庫(2)

3、 功能一,插入新的新聞到數(shù)據(jù)庫中SqlConnection con = Getconn(); con.Open(); string strsql = INSERT INTO news VALUES( + TextBox1.Text + , + TextBox2.Text + , + TextBox3.Text + ,+DateTime.Now.ToString()+); SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.ExecuteNonQuery() 0) GridView1.DataBind(); Response.Write(a

4、lert(添加成功|); TextBox1.Text = ; TextBox2.Text = ; TextBox3.Text = ;(3) 功能二,刪除發(fā)布錯(cuò)誤的新聞信息SqlConnection con = Getconn(); con.Open(); string strsql = DELETE FROM news WHERE id= + TextBox4.Text + ; SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.ExecuteNonQuery() 0) GridView1.DataBind(); Response.Wri

5、te(alert(刪?除y成功|); TextBox1.Text = ; TextBox2.Text = ; TextBox3.Text = ; TextBox4.Text = ;(4) 功能三,修改所發(fā)布的新聞SqlConnection con = Getconn(); con.Open(); string strsql = UPDATE news SET columns= + TextBox2.Text + ,title= + TextBox2.Text + ,contents= + TextBox3.Text + ,time= + DateTime.Now.ToString() + WH

6、ERE id= + TextBox4.Text + ; SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.ExecuteNonQuery() 0) GridView1.DataBind(); Response.Write(alert(修T改?成功|);(5) 功能四,顯示該ID的新聞內(nèi)容到Textbox中,以便于修改處理SqlConnection con = Getconn(); con.Open(); string strsql = select * FROM news WHERE id= + TextBox4.Text + ; Sq

7、lCommand cmd = new SqlCommand(strsql, con); SqlDataReader dr=cmd.ExecuteReader(); dr.Read(); TextBox1.Text = dr0.ToString(); TextBox2.Text = dr1.ToString(); ; TextBox3.Text = dr2.ToString(); TextBox4.Text = dr4.ToString();(詳細(xì)見實(shí)驗(yàn)源代碼)實(shí) 驗(yàn) 結(jié) 果(附頁2)實(shí)驗(yàn)結(jié)果展示:實(shí) 驗(yàn) 源 代 碼(附頁2)頁面設(shè)計(jì)代碼: 采用?web方?式?發(fā)布?新?聞? asp:SqlDa

8、taSource ID=SqlDataSource1 runat=server ConnectionString= SelectCommand=SELECT * FROM news (必?填?,?插?入?數(shù)y據(jù)Y時(shí)不?用?填?)?       后臺(tái)服務(wù)端代碼:namespace Newspublish public partial class NewsPublish : System.Web.UI.Page public SqlConnection Getconn() string constr = ConfigurationManager.ConnectionS

9、tringsNewsMessageConnectionString.ConnectionString; SqlConnection con = new SqlConnection(constr); return con; protected void Page_Load(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e) try SqlConnection con = Getconn(); con.Open(); string strsql = INSERT INTO news

10、 VALUES( + TextBox1.Text + , + TextBox2.Text + , + TextBox3.Text + ,+DateTime.Now.ToString()+); SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.ExecuteNonQuery() 0) GridView1.DataBind(); Response.Write(alert(添加成功|); TextBox1.Text = ; TextBox2.Text = ; TextBox3.Text = ; else Response.Write(aler

11、t(添加失敗); con.Close(); catch (Exception a) Response.Write(a.Message.ToString(); protected void Button2_Click(object sender, EventArgs e) SqlConnection con = Getconn(); con.Open(); string strsql = DELETE FROM news WHERE id= + TextBox4.Text + ; SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.Exec

12、uteNonQuery() 0) GridView1.DataBind(); Response.Write(alert(刪?除y成功|); TextBox1.Text = ; TextBox2.Text = ; TextBox3.Text = ; TextBox4.Text = ; else Response.Write(alert(刪?除y失敗); con.Close(); protected void Button3_Click(object sender, EventArgs e) SqlConnection con = Getconn(); con.Open(); string str

13、sql = UPDATE news SET columns= + TextBox2.Text + ,title= + TextBox2.Text + ,contents= + TextBox3.Text + ,time= + DateTime.Now.ToString() + WHERE id= + TextBox4.Text + ; SqlCommand cmd = new SqlCommand(strsql, con); if (cmd.ExecuteNonQuery() 0) GridView1.DataBind(); Response.Write(alert(修T改?成功|); TextBox1.Text = ; TextBox2.Text = ; TextBox3.Text = ; TextBox4.Text = ; else Response.Write(alert(修T改?失敗); con.Close(); protected void Button5_Click(object sender, EventArgs e) SqlConnection con = Getconn(); con.Open(); string strsql = select * FROM news WHERE id= + TextBox4.Text + ; SqlCommand cmd =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論