new SqlParameter("@feedBalance",SqlDbType.Decimal,9)如何定Decimal的精读为小数点后1位?

indusl 2011-04-25 03:09:24
new SqlParameter("@feedBalance",SqlDbType.Decimal,9)如何定Decimal的精读为小数点后1位?
...全文
192 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-04-26
  • 打赏
  • 举报
回复
ToString("0.0");
indusl 2011-04-26
  • 打赏
  • 举报
回复
是要在定以得时候就指定, 不是在输出的时候
myhope88 2011-04-26
  • 打赏
  • 举报
回复
传参的时候就不需要设定了吧
马老虎 2011-04-26
  • 打赏
  • 举报
回复
传参的时候 没必要设置这个精确度
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace 教务管理系统 { public class ClassInfo : 医院管理系统.ParentForm { private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; private System.Data.SqlClient.SqlCommand sqlDeleteCommand1; private System.Data.SqlClient.SqlConnection sqlConnection1; private 教务管理系统.DataSet1 dataSet11; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txt4; private System.Windows.Forms.TextBox txt5; private System.Windows.Forms.TextBox txt6; private System.Windows.Forms.TextBox txt9; private System.Windows.Forms.TextBox txt8; private System.Windows.Forms.TextBox txt7; private System.ComponentModel.IContainer components = null; public ClassInfo() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); this.dataSet11 = new 教务管理系统.DataSet1(); this.label4 = new System.Windows.Forms.Label(); this.txt4 = new System.Windows.Forms.TextBox(); this.txt5 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.txt6 = new System.Windows.Forms.TextBox(); this.txt9 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.txt8 = new System.Windows.Forms.TextBox(); this.txt7 = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit(); // // groupBox1 // this.groupBox1.Name = "groupBox1"; // // txt2 // this.txt2.Name = "txt2"; // // label1 // this.label1.Name = "label1"; this.label1.Text = "年级"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnSearch // this.btnSearch.Name = "btnSearch"; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // txt1 // this.txt1.Name = "txt1"; // // label2 // this.label2.Name = "label2"; this.label2.Text = "班级编号"; // // txt3 // this.txt3.Name = "txt3"; // // label3 // this.label3.Name = "label3"; this.label3.Text = "班级名称"; // // toolBar1 // this.toolBar1.Name = "toolBar1"; this.toolBar1.Size = new System.Drawing.Size(728, 41); // // dataGrid1 // this.dataGrid1.DataMember = "班级信息"; this.dataGrid1.DataSource = this.dataSet11; this.dataGrid1.Name = "dataGrid1"; // // groupBox2 // this.groupBox2.Controls.Add(this.txt4); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.txt5); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.txt6); this.groupBox2.Controls.Add(this.txt9); this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label8); this.groupBox2.Controls.Add(this.txt8); this.groupBox2.Controls.Add(this.txt7); this.groupBox2.Controls.Add(this.label9); this.groupBox2.Name = "groupBox2"; // // da1 // this.da1.DeleteCommand = this.sqlDeleteCommand1; this.da1.InsertCommand = this.sqlInsertCommand1; this.da1.SelectCommand = this.sqlSelectCommand1; this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "班级信息", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("班级编号", "班级编号"), new System.Data.Common.DataColumnMapping("年级", "年级"), new System.Data.Common.DataColumnMapping("班级名称", "班级名称"), new System.Data.Common.DataColumnMapping("班级简称", "班级简称"), new System.Data.Common.DataColumnMapping("人数", "人数"), new System.Data.Common.DataColumnMapping("班主任", "班主任")})}); this.da1.UpdateCommand = this.sqlUpdateCommand1; // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 LIKE @Param4) AND (年级 " + "LIKE @Param5) AND (班级名称 LIKE @Param6)"; this.sqlSelectCommand1.Connection = this.sqlConnection1; this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param6", System.Data.SqlDbType.VarChar, 30, "班级名称")); // // sqlConnection1 // this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source=\"." + "\";persist security info=False;initial catalog=eisbook"; // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "INSERT INTO 班级信息(班级编号, 年级, 班级名称, 班级简称, 人数, 班主任) VALUES (@班级编号, @年级, @班级名称, @班级简称," + " @人数, @班主任); SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 = @班级编号)" + ""; this.sqlInsertCommand1.Connection = this.sqlConnection1; this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级名称", System.Data.SqlDbType.VarChar, 30, "班级名称")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级简称", System.Data.SqlDbType.VarChar, 16, "班级简称")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Current, null)); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班主任", System.Data.SqlDbType.VarChar, 8, "班主任")); // // sqlUpdateCommand1 // this.sqlUpdateCommand1.CommandText = @"UPDATE 班级信息 SET 班级编号 = @班级编号, 年级 = @年级, 班级名称 = @班级名称, 班级简称 = @班级简称, 人数 = @人数, 班主任 = @班主任 WHERE (班级编号 = @Original_班级编号) AND (人数 = @Original_人数 OR @Original_人数 IS NULL AND 人数 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (班主任 = @Original_班主任 OR @Original_班主任 IS NULL AND 班主任 IS NULL) AND (班级名称 = @Original_班级名称 OR @Original_班级名称 IS NULL AND 班级名称 IS NULL) AND (班级简称 = @Original_班级简称 OR @Original_班级简称 IS NULL AND 班级简称 IS NULL); SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 = @班级编号)"; this.sqlUpdateCommand1.Connection = this.sqlConnection1; this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级名称", System.Data.SqlDbType.VarChar, 30, "班级名称")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级简称", System.Data.SqlDbType.VarChar, 16, "班级简称")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Current, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班主任", System.Data.SqlDbType.VarChar, 8, "班主任")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班主任", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班主任", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级名称", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级名称", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级简称", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级简称", System.Data.DataRowVersion.Original, null)); // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = @"DELETE FROM 班级信息 WHERE (班级编号 = @Original_班级编号) AND (人数 = @Original_人数 OR @Original_人数 IS NULL AND 人数 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (班主任 = @Original_班主任 OR @Original_班主任 IS NULL AND 班主任 IS NULL) AND (班级名称 = @Original_班级名称 OR @Original_班级名称 IS NULL AND 班级名称 IS NULL) AND (班级简称 = @Original_班级简称 OR @Original_班级简称 IS NULL AND 班级简称 IS NULL)"; this.sqlDeleteCommand1.Connection = this.sqlConnection1; this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班主任", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班主任", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级名称", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级名称", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级简称", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级简称", System.Data.DataRowVersion.Original, null)); // // dataSet11 // this.dataSet11.DataSetName = "DataSet1"; this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN"); // // label4 // this.label4.Location = new System.Drawing.Point(64, 32); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(100, 16); this.label4.TabIndex = 0; this.label4.Text = "班级编号"; // // txt4 // this.txt4.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级编号")); this.txt4.Location = new System.Drawing.Point(64, 48); this.txt4.Name = "txt4"; this.txt4.ReadOnly = true; this.txt4.Size = new System.Drawing.Size(136, 21); this.txt4.TabIndex = 1; this.txt4.Text = ""; // // txt5 // this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.年级")); this.txt5.Location = new System.Drawing.Point(232, 48); this.txt5.Name = "txt5"; this.txt5.ReadOnly = true; this.txt5.Size = new System.Drawing.Size(136, 21); this.txt5.TabIndex = 1; this.txt5.Text = ""; // // label5 // this.label5.Location = new System.Drawing.Point(232, 32); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 16); this.label5.TabIndex = 0; this.label5.Text = "年级"; // // label6 // this.label6.Location = new System.Drawing.Point(408, 32); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(100, 16); this.label6.TabIndex = 0; this.label6.Text = "班级名称"; // // txt6 // this.txt6.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级名称")); this.txt6.Location = new System.Drawing.Point(408, 48); this.txt6.Name = "txt6"; this.txt6.ReadOnly = true; this.txt6.Size = new System.Drawing.Size(136, 21); this.txt6.TabIndex = 1; this.txt6.Text = ""; // // txt9 // this.txt9.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班主任")); this.txt9.Location = new System.Drawing.Point(408, 96); this.txt9.Name = "txt9"; this.txt9.ReadOnly = true; this.txt9.Size = new System.Drawing.Size(136, 21); this.txt9.TabIndex = 1; this.txt9.Text = ""; // // label7 // this.label7.Location = new System.Drawing.Point(408, 80); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(100, 16); this.label7.TabIndex = 0; this.label7.Text = "班主任"; // // label8 // this.label8.Location = new System.Drawing.Point(232, 80); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(100, 16); this.label8.TabIndex = 0; this.label8.Text = "人数"; // // txt8 // this.txt8.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级简称")); this.txt8.Location = new System.Drawing.Point(232, 96); this.txt8.Name = "txt8"; this.txt8.ReadOnly = true; this.txt8.Size = new System.Drawing.Size(136, 21); this.txt8.TabIndex = 1; this.txt8.Text = ""; // // txt7 // this.txt7.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级简称")); this.txt7.Location = new System.Drawing.Point(64, 96); this.txt7.Name = "txt7"; this.txt7.ReadOnly = true; this.txt7.Size = new System.Drawing.Size(136, 21); this.txt7.TabIndex = 1; this.txt7.Text = ""; // // label9 // this.label9.Location = new System.Drawing.Point(64, 80); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(100, 16); this.label9.TabIndex = 0; this.label9.Text = "班级简称"; // // ClassInfo // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(728, 502); this.Name = "ClassInfo"; this.Text = "【班级信息维护】"; this.Load += new System.EventHandler(this.ClassInfo_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit(); } #endregion //--------创建窗体时,读入数据------- private void ClassInfo_Load(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Size=8;//4年份输入 da1.SelectCommand.Parameters[1].Value="%"; da1.SelectCommand.Parameters[2].Value="%"; da1.Fill(dataSet11); //设置数据导航控件 this.cmOrders=(CurrencyManager) BindingContext[dataSet11,"班级信息"]; //将基类中的数据集与派生类中的数据集连接 base.dataSet11=this.dataSet11; } //-----------根据输入,检索信息---------- private void btnSearch_Click(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Value="%"; da1.SelectCommand.Parameters[2].Value="%"; if(txt1.Text.Trim()!="") { da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%"; } if(txt2.Text.Trim()!="") { da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%"; } if(txt3.Text.Trim()!="") { da1.SelectCommand.Parameters[2].Value="%"+txt3.Text.Trim()+"%"; } dataSet11.Clear();//刷新数据集 da1.Fill(dataSet11); } //----------重写设置控件只读属性函数---------- protected override void SetModifyMode(bool blnEdit) { base.SetModifyMode (blnEdit); txt4.ReadOnly=!blnEdit; txt5.ReadOnly=!blnEdit; txt6.ReadOnly=!blnEdit; txt7.ReadOnly=!blnEdit; txt8.ReadOnly=!blnEdit; txt9.ReadOnly=!blnEdit; } //-------重写新增记录时设置默认值函数-------- protected override void SetDefaultValue() { base.SetDefaultValue (); } //-------重写检查非空字段函数-------- protected override bool CheckNotNull() { if(txt4.Text.Trim()=="")// 班级编号不能为空 { MessageBox.Show("班级编号不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } return base.CheckNotNull (); } } }
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace 教务管理系统 { public class ClassInfo : 医院管理系统.ParentForm { private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; private System.Data.SqlClient.SqlCommand sqlDeleteCommand1; private System.Data.SqlClient.SqlConnection sqlConnection1; private 教务管理系统.DataSet1 dataSet11; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txt4; private System.Windows.Forms.TextBox txt5; private System.Windows.Forms.TextBox txt6; private System.Windows.Forms.TextBox txt9; private System.Windows.Forms.TextBox txt8; private System.Windows.Forms.TextBox txt7; private System.ComponentModel.IContainer components = null; public ClassInfo() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); this.dataSet11 = new 教务管理系统.DataSet1(); this.label4 = new System.Windows.Forms.Label(); this.txt4 = new System.Windows.Forms.TextBox(); this.txt5 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.txt6 = new System.Windows.Forms.TextBox(); this.txt9 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.txt8 = new System.Windows.Forms.TextBox(); this.txt7 = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit(); // // groupBox1 // this.groupBox1.Name = "groupBox1"; // // txt2 // this.txt2.Name = "txt2"; // // label1 // this.label1.Name = "label1"; this.label1.Text = "年级"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnSearch // this.btnSearch.Name = "btnSearch"; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // txt1 // this.txt1.Name = "txt1"; // // label2 // this.label2.Name = "label2"; this.label2.Text = "班级编号"; // // txt3 // this.txt3.Name = "txt3"; // // label3 // this.label3.Name = "label3"; this.label3.Text = "班级名称"; // // toolBar1 // this.toolBar1.Name = "toolBar1"; this.toolBar1.Size = new System.Drawing.Size(728, 41); // // dataGrid1 // this.dataGrid1.DataMember = "班级信息"; this.dataGrid1.DataSource = this.dataSet11; this.dataGrid1.Name = "dataGrid1"; // // groupBox2 // this.groupBox2.Controls.Add(this.txt4); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.txt5); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.txt6); this.groupBox2.Controls.Add(this.txt9); this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label8); this.groupBox2.Controls.Add(this.txt8); this.groupBox2.Controls.Add(this.txt7); this.groupBox2.Controls.Add(this.label9); this.groupBox2.Name = "groupBox2"; // // da1 // this.da1.DeleteCommand = this.sqlDeleteCommand1; this.da1.InsertCommand = this.sqlInsertCommand1; this.da1.SelectCommand = this.sqlSelectCommand1; this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "班级信息", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("班级编号", "班级编号"), new System.Data.Common.DataColumnMapping("年级", "年级"), new System.Data.Common.DataColumnMapping("班级名称", "班级名称"), new System.Data.Common.DataColumnMapping("班级简称", "班级简称"), new System.Data.Common.DataColumnMapping("人数", "人数"), new System.Data.Common.DataColumnMapping("班主任", "班主任")})}); this.da1.UpdateCommand = this.sqlUpdateCommand1; // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 LIKE @Param4) AND (年级 " + "LIKE @Param5) AND (班级名称 LIKE @Param6)"; this.sqlSelectCommand1.Connection = this.sqlConnection1; this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param6", System.Data.SqlDbType.VarChar, 30, "班级名称")); // // sqlConnection1 // this.sqlConnection1.ConnectionString = "server=.\\sqlexpress;database=eisbook;User id=sa;password=sa"; // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "INSERT INTO 班级信息(班级编号, 年级, 班级名称, 班级简称, 人数, 班主任) VALUES (@班级编号, @年级, @班级名称, @班级简称," + " @人数, @班主任); SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 = @班级编号)" + ""; this.sqlInsertCommand1.Connection = this.sqlConnection1; this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级名称", System.Data.SqlDbType.VarChar, 30, "班级名称")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级简称", System.Data.SqlDbType.VarChar, 16, "班级简称")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Current, null)); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班主任", System.Data.SqlDbType.VarChar, 8, "班主任")); // // sqlUpdateCommand1 // this.sqlUpdateCommand1.CommandText = @"UPDATE 班级信息 SET 班级编号 = @班级编号, 年级 = @年级, 班级名称 = @班级名称, 班级简称 = @班级简称, 人数 = @人数, 班主任 = @班主任 WHERE (班级编号 = @Original_班级编号) AND (人数 = @Original_人数 OR @Original_人数 IS NULL AND 人数 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (班主任 = @Original_班主任 OR @Original_班主任 IS NULL AND 班主任 IS NULL) AND (班级名称 = @Original_班级名称 OR @Original_班级名称 IS NULL AND 班级名称 IS NULL) AND (班级简称 = @Original_班级简称 OR @Original_班级简称 IS NULL AND 班级简称 IS NULL); SELECT 班级编号, 年级, 班级名称, 班级简称, 人数, 班主任 FROM 班级信息 WHERE (班级编号 = @班级编号)"; this.sqlUpdateCommand1.Connection = this.sqlConnection1; this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 14, "班级编号")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级名称", System.Data.SqlDbType.VarChar, 30, "班级名称")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级简称", System.Data.SqlDbType.VarChar, 16, "班级简称")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Current, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班主任", System.Data.SqlDbType.VarChar, 8, "班主任")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班主任", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班主任", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级名称", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级名称", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级简称", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级简称", System.Data.DataRowVersion.Original, null)); // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = @"DELETE FROM 班级信息 WHERE (班级编号 = @Original_班级编号) AND (人数 = @Original_人数 OR @Original_人数 IS NULL AND 人数 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (班主任 = @Original_班主任 OR @Original_班主任 IS NULL AND 班主任 IS NULL) AND (班级名称 = @Original_班级名称 OR @Original_班级名称 IS NULL AND 班级名称 IS NULL) AND (班级简称 = @Original_班级简称 OR @Original_班级简称 IS NULL AND 班级简称 IS NULL)"; this.sqlDeleteCommand1.Connection = this.sqlConnection1; this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_人数", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(3)), ((System.Byte)(0)), "人数", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班主任", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班主任", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级名称", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级名称", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级简称", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级简称", System.Data.DataRowVersion.Original, null)); // // dataSet11 // this.dataSet11.DataSetName = "DataSet1"; this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN"); // // label4 // this.label4.Location = new System.Drawing.Point(64, 32); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(100, 16); this.label4.TabIndex = 0; this.label4.Text = "班级编号"; // // txt4 // this.txt4.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级编号")); this.txt4.Location = new System.Drawing.Point(64, 48); this.txt4.Name = "txt4"; this.txt4.ReadOnly = true; this.txt4.Size = new System.Drawing.Size(136, 21); this.txt4.TabIndex = 1; this.txt4.Text = ""; // // txt5 // this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.年级")); this.txt5.Location = new System.Drawing.Point(232, 48); this.txt5.Name = "txt5"; this.txt5.ReadOnly = true; this.txt5.Size = new System.Drawing.Size(136, 21); this.txt5.TabIndex = 1; this.txt5.Text = ""; // // label5 // this.label5.Location = new System.Drawing.Point(232, 32); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 16); this.label5.TabIndex = 0; this.label5.Text = "年级"; // // label6 // this.label6.Location = new System.Drawing.Point(408, 32); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(100, 16); this.label6.TabIndex = 0; this.label6.Text = "班级名称"; // // txt6 // this.txt6.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级名称")); this.txt6.Location = new System.Drawing.Point(408, 48); this.txt6.Name = "txt6"; this.txt6.ReadOnly = true; this.txt6.Size = new System.Drawing.Size(136, 21); this.txt6.TabIndex = 1; this.txt6.Text = ""; // // txt9 // this.txt9.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班主任")); this.txt9.Location = new System.Drawing.Point(408, 96); this.txt9.Name = "txt9"; this.txt9.ReadOnly = true; this.txt9.Size = new System.Drawing.Size(136, 21); this.txt9.TabIndex = 1; this.txt9.Text = ""; // // label7 // this.label7.Location = new System.Drawing.Point(408, 80); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(100, 16); this.label7.TabIndex = 0; this.label7.Text = "班主任"; // // label8 // this.label8.Location = new System.Drawing.Point(232, 80); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(100, 16); this.label8.TabIndex = 0; this.label8.Text = "人数"; // // txt8 // this.txt8.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级简称")); this.txt8.Location = new System.Drawing.Point(232, 96); this.txt8.Name = "txt8"; this.txt8.ReadOnly = true; this.txt8.Size = new System.Drawing.Size(136, 21); this.txt8.TabIndex = 1; this.txt8.Text = ""; // // txt7 // this.txt7.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "班级信息.班级简称")); this.txt7.Location = new System.Drawing.Point(64, 96); this.txt7.Name = "txt7"; this.txt7.ReadOnly = true; this.txt7.Size = new System.Drawing.Size(136, 21); this.txt7.TabIndex = 1; this.txt7.Text = ""; // // label9 // this.label9.Location = new System.Drawing.Point(64, 80); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(100, 16); this.label9.TabIndex = 0; this.label9.Text = "班级简称"; // // ClassInfo // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(728, 502); this.Name = "ClassInfo"; this.Text = "【班级信息维护】"; this.Load += new System.EventHandler(this.ClassInfo_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit(); } #endregion //--------创建窗体时,读入数据------- private void ClassInfo_Load(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Size=8;//4年份输入 da1.SelectCommand.Parameters[1].Value="%"; da1.SelectCommand.Parameters[2].Value="%"; da1.Fill(dataSet11); //设置数据导航控件 this.cmOrders=(CurrencyManager) BindingContext[dataSet11,"班级信息"]; //将基类中的数据集与派生类中的数据集连接 base.dataSet11=this.dataSet11; } //-----------根据输入,检索信息---------- private void btnSearch_Click(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Value="%"; da1.SelectCommand.Parameters[2].Value="%"; if(txt1.Text.Trim()!="") { da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%"; } if(txt2.Text.Trim()!="") { da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%"; } if(txt3.Text.Trim()!="") { da1.SelectCommand.Parameters[2].Value="%"+txt3.Text.Trim()+"%"; } dataSet11.Clear();//刷新数据集 da1.Fill(dataSet11); } //----------重写设置控件只读属性函数---------- protected override void SetModifyMode(bool blnEdit) { base.SetModifyMode (blnEdit); txt4.ReadOnly=!blnEdit; txt5.ReadOnly=!blnEdit; txt6.ReadOnly=!blnEdit; txt7.ReadOnly=!blnEdit; txt8.ReadOnly=!blnEdit; txt9.ReadOnly=!blnEdit; } //-------重写新增记录时设置默认值函数-------- protected override void SetDefaultValue() { base.SetDefaultValue (); } //-------重写检查非空字段函数-------- protected override bool CheckNotNull() { if(txt4.Text.Trim()=="")// 班级编号不能为空 { MessageBox.Show("班级编号不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } return base.CheckNotNull (); } } }
public void AddItem(string cartID, int bookID, int quantity) { // 新建Connection和Command对象 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartAddItem", myConnection); // 指命令对象为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 为存储过程添加参数信息 SqlParameter parameterBookID = new SqlParameter("@BookID", SqlDbType.Int, 4); parameterBookID.Value = bookID; myCommand.Parameters.Add(parameterBookID); SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4); parameterQuantity.Value = quantity; myCommand.Parameters.Add(parameterQuantity); // 打开连接并执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); } /// /// 获取购物车图书总数量 /// /// /// public int GetItemCount(string cartID) { // 新建Connection和Command对象 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartItemCount", myConnection); // 指命令类型为存储过程 myCommand.CommandType = CommandType.StoredProcedure; SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); // 添加输出参数 SqlParameter parameterItemCount = new SqlParameter("@ItemCount", SqlDbType.Int, 4); //指参数类型为输出参数 parameterItemCount.Direction = ParameterDirection.Output; myCommand.Parameters.Add(parameterItemCount); // 打开连接并执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); // 通过存储过程的输出参数来返回购物车总图书量 return ((int)parameterItemCount.Value); } /// /// 根据购物车ID获取购物车信息 /// /// 购物车ID /// DataReader:购物车具体信息 public SqlDataReader GetItems(string cartID) { // 新建Connection和Command实例 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartList", myConnection); // 指命令为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 添加参数购物车编号到存储过程 SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); // 打开连接,执行操作 myConnection.Open(); SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // 返回数据读取器 return result; } /// /// 获取购物车中图书的总价 /// /// 购物车编号 /// 总价 public decimal GetTotal(string cartID) { // 新建Connection和Command对象 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartTotal", myConnection); // 指命令类型为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 添加参数到存储过程 SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); //添加输出总价的参数到存储过程 SqlParameter parameterTotalCost = new SqlParameter("@TotalCost", SqlDbType.Money, 8); parameterTotalCost.Direction = ParameterDirection.Output; myCommand.Parameters.Add(parameterTotalCost); // 打开连接,执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); // 返回结果 if (parameterTotalCost.Value.ToString() != "") { return (decimal)parameterTotalCost.Value; } else { return 0; } } /// /// 合并购物车:用于合并用户登陆前和登陆后的购物车 /// /// 登陆前的购物车ID /// 登陆后的购物车ID public void MigrateCart(String oldCartId, String newCartId) { // 新建Connection和Command实例 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartMigrate", myConnection); // 指操作类型为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 添加参数到存储过程 SqlParameter cart1 = new SqlParameter("@OriginalCartId ", SqlDbType.NVarChar, 50); cart1.Value = oldCartId; myCommand.Parameters.Add(cart1); SqlParameter cart2 = new SqlParameter("@NewCartId ", SqlDbType.NVarChar, 50); cart2.Value = newCartId; myCommand.Parameters.Add(cart2); // 打开连接,执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); } /// /// 删除购物车中的图书 /// /// 购物车编号 /// 图书编号 public void RemoveItem(string cartID, int bookID) { // 新建Connection和Command实例 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartRemoveItem", myConnection); // 指操作类型为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 添加参数给存储过程 SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4); parameterProductID.Value = bookID; myCommand.Parameters.Add(parameterProductID); SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); // 打开连接,执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); } /// /// 更新购物车中图书信息 /// /// 购物车编号 /// 图书编号 /// 图书数量 public void UpdateItem(string cartID, int productID, int quantity) { // 如果输入数量小于0则抛出异常 if (quantity < 0) { throw new Exception("Quantity cannot be a negative number"); } // 新建Connection和Command实例 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("ShoppingCartUpdate", myConnection); // 指操作为存储过程 myCommand.CommandType = CommandType.StoredProcedure; // 添加参数给存储过程 SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4); parameterProductID.Value = productID; myCommand.Parameters.Add(parameterProductID); SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50); parameterCartID.Value = cartID; myCommand.Parameters.Add(parameterCartID); SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4); parameterQuantity.Value = quantity; myCommand.Parameters.Add(parameterQuantity); // 打开连接,执行操作 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close();

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧