濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > ASP.NET書(shū)籍信息錄入實(shí)現(xiàn)代碼

ASP.NET書(shū)籍信息錄入實(shí)現(xiàn)代碼

熱門標(biāo)簽:云南外呼系統(tǒng)代理 辦公用地圖標(biāo)注網(wǎng)點(diǎn)怎么操作 海東防封電銷卡 聊城智能電銷機(jī)器人電話 上海市三維地圖標(biāo)注 寧德防封版電銷卡 南昌自動(dòng)外呼系統(tǒng)線路 安陸市地圖標(biāo)注app 西寧電銷外呼系統(tǒng)公司

1、 在數(shù)據(jù)庫(kù)中建立一個(gè)test數(shù)據(jù)庫(kù),在test數(shù)據(jù)庫(kù)中建立一個(gè)book_info表。
       Book_name      varchar(100)
        Author               varchar(50)
         Press               varchar(50)
       Press_date      varchar(20)
         Image              varchar(30)

2、 制作一個(gè)如下頁(yè)面:

當(dāng)單擊“插入圖書(shū)信息”按鈕時(shí),將用戶的信息保存到book_info表中。注意:封面圖片要求先上傳到網(wǎng)站根目錄下的“upload”文件夾中,再將圖片在網(wǎng)站中的相對(duì)路徑保存到數(shù)據(jù)庫(kù)book_info表的Image字段中。
布局代碼:

%@ 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 runat="server"> 
 title>/title> 
/head> 
body> 
 form id="form1" runat="server"> 
  table> 
   tr> 
   td>asp:Label ID="Label1" runat="server" Text="書(shū)名:">/asp:Label>/td> 
   td>asp:TextBox ID="TextBox1" 
    runat="server">/asp:TextBox> 
    /td> 
   /tr> 
   tr> 
    td>asp:Label ID="Label2" runat="server" Text="作者:">/asp:Label>/td> 
   td> asp:TextBox ID="TextBox2" 
     runat="server">/asp:TextBox>/td> 
    /tr> 
    tr> 
     td> asp:Label ID="Label3" runat="server" Text="出版社:">/asp:Label>/td> 
     td>asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> 
     asp:ListItem>清華大學(xué)出版社/asp:ListItem> 
     asp:ListItem>機(jī)械工業(yè)出版社/asp:ListItem> 
     asp:ListItem>人民郵電出版社/asp:ListItem> 
     asp:ListItem>電子工業(yè)出版社/asp:ListItem> 
    /asp:DropDownList>/td> 
    /tr> 
    tr> 
    td>asp:Label ID="Label4" runat="server" Text="出版日期:">/asp:Label>/td> 
     td>asp:Calendar ID="Calendar1" runat="server">/asp:Calendar>/td> 
     /tr> 
     tr> 
     td> 
      asp:Label ID="Label5" runat="server" Text="封面圖片:">/asp:Label>/td> 
     td> 
      asp:FileUpload ID="FileUpload1" runat="server" />/td> 
     /tr> 
     tr> 
     td>/td> 
     td> 
      asp:Button ID="Button1" runat="server" Text="插入圖片信息" onclick="Button1_Click" />/td> 
     /tr> 
    /table> 
 /form> 
 
/body> 
/html> 

cs代碼

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
 
public partial class _Default : System.Web.UI.Page 
{ 
 protected void Page_Load(object sender, EventArgs e) 
 { 
 
 } 
 protected void Button1_Click(object sender, EventArgs e) 
 { 
  string savePath = Server.MapPath("~/images/"); 
  if (FileUpload1.HasFile) 
  { 
   String fileName = FileUpload1.FileName; 
   savePath += fileName; 
   FileUpload1.SaveAs(savePath); 
  } 
  string sql = "Data Source=A25;Initial Catalog=test;Integrated Security=True"; 
  string sqlStr = @"Insert into book_info(Book_name,Author,Press,Press_date,Image) values 
    ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.SelectedItem.Text + "','" 
     + Calendar1.SelectedDate.ToShortDateString() + "','" + FileUpload1.FileName + "')"; 
  using (SqlConnection conn = new SqlConnection(sql)) 
  { 
   conn.Open(); 
   using (SqlCommand cmd = conn.CreateCommand()) 
   { 
    cmd.CommandText = sqlStr; 
    cmd.ExecuteNonQuery(); 
   } 
  } 
  Response.Write("插入成功!"); 
 } 
} 

以上就是本文的全部?jī)?nèi)容,希望可以給大家一個(gè)啟發(fā),對(duì)大家的學(xué)習(xí)有所幫助。

您可能感興趣的文章:
  • 又一波Java專業(yè)人士必備書(shū)籍來(lái)襲
  • Java自學(xué)書(shū)籍Top 10
  • 8個(gè)簡(jiǎn)單部分開(kāi)啟Java語(yǔ)言學(xué)習(xí)之路 附j(luò)ava學(xué)習(xí)書(shū)單
  • 推薦幾本學(xué)習(xí)java的書(shū)籍
  • 一個(gè)合格的程序員應(yīng)該讀過(guò)哪些書(shū)(偏java)
  • 快速入門的一些C\C++書(shū)籍
  • JavaScript入門學(xué)習(xí)書(shū)籍推薦
  • 推薦幾本Android程序員必讀書(shū)籍

標(biāo)簽:崇左 洛陽(yáng) 汕尾 青海 南寧 衢州 贛州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET書(shū)籍信息錄入實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ASP.NET,書(shū)籍,信息,錄入,實(shí)現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET書(shū)籍信息錄入實(shí)現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ASP.NET書(shū)籍信息錄入實(shí)現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    包头市| 富锦市| 华坪县| 嘉禾县| 小金县| 苏尼特右旗| 龙里县| 延川县| 化州市| 罗山县| 永福县| 凌海市| 鹤岗市| 肥西县| 金川县| 江阴市| 缙云县| 河池市| 灌阳县| 南宁市| 宝鸡市| 望都县| 祁阳县| 龙江县| 赞皇县| 绩溪县| 田东县| 万全县| 铁岭县| 新和县| 磴口县| 吉木乃县| 清镇市| 蓝山县| 永修县| 临武县| 长垣县| 平利县| 霞浦县| 赤壁市| 广丰县|