📄 bookadd.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
using System.Data .SqlClient ;
namespace BMS
{
//该源码下载自www.51aspx.com(51aspx.com)
/// <summary>
/// BookAdd 的摘要说明。
/// </summary>
public partial class BookAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void btn_submit_Click(object sender, System.EventArgs e)
{
if(Page.IsValid )
{//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的LMS数据库,创建两连接
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlConnection cn2= new SqlConnection (strconn);
cn2.Open ();
//利用Command对象调用存储过程,创建添加book表命令类型
SqlCommand cmbookadd=new SqlCommand ("bookadd",cn);
//将命令类型转为存储类型
cmbookadd.CommandType =CommandType.StoredProcedure ;
//添加并给参数付值
cmbookadd.Parameters .Add ("@BID",SqlDbType.Int);
cmbookadd.Parameters .Add ("@BISBN",SqlDbType.VarChar);
cmbookadd.Parameters .Add ("@BName",SqlDbType.VarChar);
cmbookadd.Parameters .Add ("@BAuthor",SqlDbType.VarChar);
cmbookadd.Parameters .Add ("@BPress",SqlDbType.VarChar );
cmbookadd.Parameters .Add ("@BTheme",SqlDbType.VarChar );
cmbookadd.Parameters .Add ("@BClassifyText",SqlDbType.VarChar );
cmbookadd.Parameters .Add ("@BIndex",SqlDbType.VarChar );
cmbookadd.Parameters .Add ("@BPrice",SqlDbType.Money );
cmbookadd.Parameters .Add ("@BSeriesName",SqlDbType.VarChar );
cmbookadd.Parameters .Add ("@BDescribe",SqlDbType.VarChar);
//利用Command对象调用存储过程,创建添加BookMaxBIDGet表命令类型
//该类型返回我们所要往book,bookprice表中添加的BID值
SqlCommand cmbookmaxbidget=new SqlCommand ("BookMaxBIDGet ",cn2);
//将命令类型转为存储类型
cmbookmaxbidget.CommandType =CommandType.StoredProcedure ;
//添加并给参数付值
cmbookmaxbidget.Parameters .Add ("@maxbid",SqlDbType.Int);
//将BookMaxBIDGet过程参数输出
cmbookmaxbidget.Parameters ["@maxbid"].Direction =ParameterDirection.Output ;
cmbookmaxbidget.ExecuteReader ();
string maxbidstring=cmbookmaxbidget.Parameters ["@maxbid"].Value.ToString();
//考虑数据库为空的情况,maxbidstring将为空
int maxbid ;
if(maxbidstring=="")//如果数据库为空
{maxbid=20000 ;
}
else//如果数据库有数据
{maxbid=Convert.ToInt32(maxbidstring)+1 ; //取出表中BID的最大值作为下一纪录的BID
}
//往book表中参数付值
cmbookadd.Parameters ["@BID"].Value =maxbid;
cmbookadd.Parameters ["@BName"].Value =tbx_bname.Text .ToString ();
cmbookadd.Parameters ["@BISBN"].Value =tbx_bisbn.Text .ToString ();
cmbookadd.Parameters ["@BAuthor"].Value =tbx_bauthor.Text .ToString ();
cmbookadd.Parameters ["@BPress"].Value =tbx_bpress.Text .ToString ();
cmbookadd.Parameters ["@BTheme"].Value =tbx_btheme.Text .ToString ();
cmbookadd.Parameters ["@BClassifyText"].Value =tbx_bclassifytext.Text .ToString ();
cmbookadd.Parameters ["@BIndex"].Value =tbx_bindex.Text .ToString ();
cmbookadd.Parameters ["@BPrice"].Value =Convert.ToDouble (tbx_bprice.Text .ToString ());
cmbookadd.Parameters ["@BSeriesName"].Value =tbx_bseriesname.Text .ToString ();
cmbookadd.Parameters ["@BDescribe"].Value =tbx_bdescribe.Text .ToString ();
cmbookadd.ExecuteNonQuery ();
//关闭连接
cn.Close();
cn2.Close ();
Response.Redirect("bookmanage.aspx");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -