探讨:对DataGrid中数据的编辑是用SqlCommand还是DataSet.UpDate方法?

junqilian 2003-10-17 09:12:24

对DataGrid中的数据进行删除、更新是最常用的功能了,我想和各位探讨一下,对这些数据的更新是用SqlCommand执行“update,insert”等SQL语句直接在数据库更改好还是利用DataSet的修改方法现在Dataset里更改然后在update回数据库好呢?

用SqlCommand执行SQL语句直接修改了数据库,但是由于DataSet是面向非连接的,数据库更改之后如果不重新读入数据客户就感知不到数据库的更改,所有每次在DataGrid_onUpdate方法中最后对DataGrid进行绑定时都要重新建立DataSet,重新绑定。

用DataSet的方法先更改DataSet,(我理解DataSet就是数据库的内存影像),然后在有DataSet的通过DataAdapter把数据更改情况更新回数据库。这样可能更好些。

我是初学者,看到网上的一些代码都是用的第一种方法,可我在实际用的时候感觉不太好。大家在作真正的项目时会怎么写?
...全文
73 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
junqilian 2003-10-21
  • 打赏
  • 举报
回复
在定一项
Abac 2003-10-17
  • 打赏
  • 举报
回复
数据量少的时候用SQLCommand,方便,快;
需要批量修改数据和批量更新时用Adapter,但用的不多。
xavier_lee 2003-10-17
  • 打赏
  • 举报
回复
using SqlDataAdapter.Update maybe good.

but I don't use it.
haoliqi 2003-10-17
  • 打赏
  • 举报
回复
SQLCommand速度快
junqilian 2003-10-17
  • 打赏
  • 举报
回复
如果用SqlCommand直接绕过Adapter对数据库进行的更新,那就必须在更新完毕后重新读入数据在对DataGrid进行绑定,客户端才能看到更新结果了,这样的话即使放在cache里也是要重新更新cache的吧
513 2003-10-17
  • 打赏
  • 举报
回复
用SQLCommand,比较容易调试,也相对比较灵活,因为字符串灵活
mynull 2003-10-17
  • 打赏
  • 举报
回复
没错 SqlCommand 可靠
cm8983 2003-10-17
  • 打赏
  • 举报
回复
使用sqlcommand
asam2183 2003-10-17
  • 打赏
  • 举报
回复
如果只是对一条记录的更新,用SqlCmmand当然快一点
suguanqun 2003-10-17
  • 打赏
  • 举报
回复
多用SqlCommand,感觉方便些!
acewang 2003-10-17
  • 打赏
  • 举报
回复
我喜欢SqlCommand,很少用SqlDataAdapter.Update
menuvb 2003-10-17
  • 打赏
  • 举报
回复
我一般都是使用sqlcommand来更新的,感觉这个可靠点,不会出什么错误
但有时例外,比如我无法确定where 条件是而只能确定当前行的时候,只能用dataset来更新记录
goody9807 2003-10-17
  • 打赏
  • 举报
回复
你可以把dataset放入cache对象中,可以提高效率。
LineCorner 2003-10-17
  • 打赏
  • 举报
回复
web应用:用SqlCommand
window应用:用sqldataadapter或oledbdataadapter.update
comy 2003-10-17
  • 打赏
  • 举报
回复
用SqlCommand,你可以测试一下,用dataset更新同样的一条记录,可以明显感觉到用SqlCommand快很多.
1,主界面 2查询功能 ‘ private void chaxun_Click(object sender, System.EventArgs e) { SqlConnection thisConnection=new SqlConnection("Data Source=LocalHost;Integrated Security=SSPI;Initial Catalog=李梦然07060021"); //表示到SQL Server的一个实例的连接 SqlCommand thisCommand=new SqlCommand("select * from student where sno='"+textBox1.Text+"'",thisConnection); SqlDataAdapter thisAdapter=new SqlDataAdapter(); thisAdapter.SelectCommand=thisCommand; DataSet thisDataSet=new DataSet(); thisConnection.Open(); thisAdapter.Fill(thisDataSet, "student"); //在运行时设置 dataGrid1的数据源和数据成员属性,即在dataGrid1显示数据数据 dataGrid1.SetDataBinding(thisDataSet,"student"); thisConnection.Close(); } 3浏览功能 private void liulan_Click(object sender, System.EventArgs e) { //用SqlConnection对象连接SQL Server数据库魏菊丽20086666 SqlConnection thisConnection=new SqlConnection("Data Source=LocalHost;Integrated Security=SSPI;Initial Catalog=李梦然07060021"); SqlDataAdapter thisAdapter=new SqlDataAdapter(); DataSet thisDataSet=new DataSet(); //创建并返回一个与SqlConnection相关联的SqlCommand 对象 SqlCommand thisCommand=thisConnection.CreateCommand(); thisCommand.CommandText="select * from student";//获取或设置要对数据源执行的SQL语句 thisAdapter.SelectCommand =thisCommand ;//获取一个SQL语句,用于在数据选择记录 thisConnection.Open();//打开本次设置的数据库连接 thisAdapter.Fill(thisDataSet,"student");//将以上在数据源student选择的记录的所有行填充到数据。 thisConnection.Close();//断开本次数据库连接 //在运行时设置 dataGrid1的数据源和数据成员属性,即在dataGrid1显示数据数据 dataGrid1.SetDataBinding(thisDataSet,"student"); } 4,插入一个新列 private void button1_Click(object sender, System.EventArgs e) { SqlConnection thisConnection=new SqlConnection("Data Source=LocalHost;Integrated Security=SSPI;Initial Catalog=李梦然07060021"); SqlDataAdapter thisAdapter=new SqlDataAdapter(); DataSet thisDataSet=new DataSet(); SqlCommand thisCommand=thisConnection.CreateCommand(); thisCommand.CommandText="select * from student "; thisAdapter.SelectCommand =thisCommand ; thisConnection.Open(); SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter); thisAdapter.Fill(thisDataSet, "student"); DataRow thisRow=thisDataSet.Tables["student"].NewRow();//在 数据集的student Table创建新行 thisRow["sno"]="21";thisRow["sname"]="李梦然";thisRow["ssex"]="男";thisRow["thirthday"]="1987-7-31";thisRow["class"]="95001";//设置新行的个字段值 thisDataSet.Tables["student"].Rows.Add(thisRow);//将新行添加到数据集的student Table thisAdapter.Update(thisDataSet,"student");// 修改数据库表 //以下显示添加后表数据 thisCommand.CommandText="select * from student "; thisAdapter.SelectCommand =thisCommand ; dataGrid1.SetDataBinding(thisDataSet,"student"); thisConnection.Close(); }
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 (); } } }
一个关于C#写的酒店管理系统。。 using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace 酒店管理系统 { public class ClientConsume : 医院管理系统.ParentForm { public static string RZid;//入住单编号 private System.Data.SqlClient.SqlConnection sqlConnection1; private 酒店管理系统.DataSet2 dataSet21; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox txt4; private System.Windows.Forms.TextBox txt5; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox txt6; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; private System.Windows.Forms.ComboBox cmb1; private System.Windows.Forms.ComboBox cmb2; private System.Windows.Forms.Button btnSelect; private System.Windows.Forms.MonthCalendar calen1; 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.ComponentModel.IContainer components = null; public ClientConsume() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClientConsume)); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.dataSet21 = new 酒店管理系统.DataSet2(); 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.txt6 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.cmb1 = new System.Windows.Forms.ComboBox(); this.cmb2 = new System.Windows.Forms.ComboBox(); this.btnSelect = new System.Windows.Forms.Button(); this.calen1 = new System.Windows.Forms.MonthCalendar(); this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Name = "groupBox1"; // // txt2 // this.txt2.Name = "txt2"; // // label1 // this.label1.Name = "label1"; this.label1.Text = "消费内容"; // // 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"; this.txt3.Visible = false; // // label3 // this.label3.Name = "label3"; this.label3.Visible = false; // // toolBar1 // this.toolBar1.Name = "toolBar1"; this.toolBar1.Size = new System.Drawing.Size(728, 41); // // dataGrid1 // this.dataGrid1.DataMember = "帐单明细"; this.dataGrid1.DataSource = this.dataSet21; this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(728, 240); // // groupBox2 // this.groupBox2.Controls.Add(this.btnSelect); this.groupBox2.Controls.Add(this.cmb1); 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.txt6); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label8); this.groupBox2.Controls.Add(this.cmb2); this.groupBox2.Location = new System.Drawing.Point(0, 336); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(728, 160); // // 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; // // sqlConnection1 // this.sqlConnection1.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=hotelbook;Integrated Security=True"; // // dataSet21 // this.dataSet21.DataSetName = "DataSet2"; this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN"); // // label4 // this.label4.Location = new System.Drawing.Point(96, 16); 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.dataSet21, "帐单明细.入住单号")); this.txt4.Location = new System.Drawing.Point(96, 32); this.txt4.Name = "txt4"; this.txt4.ReadOnly = true; this.txt4.Size = new System.Drawing.Size(176, 21); this.txt4.TabIndex = 1; this.txt4.Text = ""; // // txt5 // this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费金额")); this.txt5.Location = new System.Drawing.Point(96, 80); this.txt5.Name = "txt5"; this.txt5.ReadOnly = true; this.txt5.Size = new System.Drawing.Size(176, 21); this.txt5.TabIndex = 1; this.txt5.Text = ""; // // label5 // this.label5.Location = new System.Drawing.Point(96, 64); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 16); this.label5.TabIndex = 0; this.label5.Text = "消费金额"; // // txt6 // this.txt6.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.备注")); this.txt6.Location = new System.Drawing.Point(96, 128); this.txt6.Name = "txt6"; this.txt6.ReadOnly = true; this.txt6.Size = new System.Drawing.Size(464, 21); this.txt6.TabIndex = 1; this.txt6.Text = ""; // // label6 // this.label6.Location = new System.Drawing.Point(96, 112); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(100, 16); this.label6.TabIndex = 0; this.label6.Text = "备注"; // // label7 // this.label7.Location = new System.Drawing.Point(352, 16); 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(352, 64); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(100, 16); this.label8.TabIndex = 0; this.label8.Text = "消费内容"; // // cmb1 // this.cmb1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费时间")); this.cmb1.Enabled = false; this.cmb1.Location = new System.Drawing.Point(352, 32); this.cmb1.Name = "cmb1"; this.cmb1.Size = new System.Drawing.Size(208, 20); this.cmb1.TabIndex = 2; this.cmb1.DropDown += new System.EventHandler(this.cmb1_DropDown); this.cmb1.Leave += new System.EventHandler(this.cmb1_Leave); // // cmb2 // this.cmb2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费内容")); this.cmb2.Enabled = false; this.cmb2.Items.AddRange(new object[] { "加收房费", "加收水电费", "视频点播费", "宽带上网费", "商品使用费", "其他费用"}); this.cmb2.Location = new System.Drawing.Point(352, 80); this.cmb2.Name = "cmb2"; this.cmb2.Size = new System.Drawing.Size(208, 20); this.cmb2.TabIndex = 2; // // btnSelect // this.btnSelect.Enabled = false; this.btnSelect.Image = ((System.Drawing.Image)(resources.GetObject("btnSelect.Image"))); this.btnSelect.Location = new System.Drawing.Point(280, 32); this.btnSelect.Name = "btnSelect"; this.btnSelect.Size = new System.Drawing.Size(24, 24); this.btnSelect.TabIndex = 73; this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click); this.btnSelect.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnSelect_MouseUp); // // calen1 // this.calen1.Location = new System.Drawing.Point(432, 208); this.calen1.Name = "calen1"; this.calen1.TabIndex = 131; this.calen1.Visible = false; this.calen1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.calen1_DateSelected); // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (入住单号 LIKE @Param3) AND (" + "消费内容 LIKE @Param4 OR 消费内容 IS NULL)"; this.sqlSelectCommand1.Connection = this.sqlConnection1; this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param3", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 40, "消费内容")); // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "INSERT INTO 帐单明细(入住单号, 消费内容, 消费金额, 消费时间, 备注) VALUES (@入住单号, @消费内容, @消费金额, @消费时间, " + "@备注); SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (帐单编号 = @@IDENTITY" + ")"; this.sqlInsertCommand1.Connection = this.sqlConnection1; this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入住单号", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费内容", System.Data.SqlDbType.VarChar, 40, "消费内容")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费金额", System.Data.SqlDbType.Money, 8, "消费金额")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费时间", System.Data.SqlDbType.DateTime, 4, "消费时间")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@备注", System.Data.SqlDbType.VarChar, 80, "备注")); // // sqlUpdateCommand1 // this.sqlUpdateCommand1.CommandText = @"UPDATE 帐单明细 SET 入住单号 = @入住单号, 消费内容 = @消费内容, 消费金额 = @消费金额, 消费时间 = @消费时间, 备注 = @备注 WHERE (帐单编号 = @Original_帐单编号) AND (入住单号 = @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); SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (帐单编号 = @帐单编号)"; this.sqlUpdateCommand1.Connection = this.sqlConnection1; this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入住单号", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费内容", System.Data.SqlDbType.VarChar, 40, "消费内容")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费金额", System.Data.SqlDbType.Money, 8, "消费金额")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费时间", System.Data.SqlDbType.DateTime, 4, "消费时间")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@备注", System.Data.SqlDbType.VarChar, 80, "备注")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_帐单编号", System.Data.SqlDbType.Int, 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, 36, 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, 80, 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, 40, 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.DateTime, 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.Money, 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("@帐单编号", System.Data.SqlDbType.Int, 4, "帐单编号")); // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = @"DELETE FROM 帐单明细 WHERE (帐单编号 = @Original_帐单编号) AND (入住单号 = @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)"; this.sqlDeleteCommand1.Connection = this.sqlConnection1; this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_帐单编号", System.Data.SqlDbType.Int, 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, 36, 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, 80, 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, 40, 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.DateTime, 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.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费金额", System.Data.DataRowVersion.Original, null)); // // ClientConsume // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(728, 502); this.Controls.Add(this.calen1); this.Name = "ClientConsume"; this.Text = "【消费记帐】"; this.Load += new System.EventHandler(this.ClientConsume_Load); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.toolBar1, 0); this.Controls.SetChildIndex(this.dataGrid1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.calen1, 0); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit(); this.ResumeLayout(false); } #endregion //-----显示和消费日期----- private void cmb1_DropDown(object sender, System.EventArgs e) { selectDate(cmb1); } //----------关闭日期控件的显示---------- private void cmb1_Leave(object sender, System.EventArgs e) { calen1.Visible=false; } //-----------单击下拉列表框下拉箭头时显示日期以供选择--------------- private void selectDate(ComboBox cb) { calen1.Left=cb.Left;//设置日期控件的位置 calen1.Top=cb.Top-calen1.Height-10+groupBox2.Top; if(cb.Text.Trim()!="") { calen1.SelectionStart=Convert.ToDateTime(cb.Text);//日历显示的时间为数据时间 calen1.SelectionEnd=Convert.ToDateTime(cb.Text); } calen1.Visible=true;//显示日期 calen1.Show(); } //-----------从日历控件选择日期信息------------ private void calen1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e) { cmb1.Text=calen1.SelectionEnd.ToString(); } //-------------根据输入选择消费数据--------------- private void btnSearch_Click(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].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()+"%"; } dataSet21.Clear();//刷新数据集 da1.Fill(dataSet21); } private void ClientConsume_Load(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Value="%"; da1.Fill(dataSet21);//填充帐单明细 base.dataSet11=this.dataSet21; this.cmOrders=(CurrencyManager) BindingContext[dataSet21,"帐单明细"]; } //----------重写设置控件只读属性函数---------- protected override void SetModifyMode(bool blnEdit) { base.SetModifyMode (blnEdit); txt5.ReadOnly=!blnEdit; txt6.ReadOnly=!blnEdit; cmb1.Enabled=blnEdit; cmb2.Enabled=blnEdit; btnSelect.Enabled=blnEdit; } //-------重写新增记录时设置默认值函数-------- protected override void SetDefaultValue() { base.SetDefaultValue(); } //-------重写检查非空字段函数-------- protected override bool CheckNotNull() { if(txt4.Text.Trim()=="")// 检查入住单号 { MessageBox.Show("入住单号号不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } if(txt5.Text.Trim()=="")//检查消费金额 { MessageBox.Show("请输入消费金额","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } return base.CheckNotNull (); } //----------从入住单双击选择入住单号----------- private void btnSelect_Click(object sender, System.EventArgs e) { string sql="select * from 入住单"; SelectTable newfrm=new SelectTable(sql,2); newfrm.Text="双击选择入住单号"; newfrm.ShowDialog(); } private void btnSelect_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(RZid=="") return; txt4.Text=RZid; } } }
不定项选择题(共14题,单选或多选): 一、一个HTML文档必须包含三个元素,它们是head、html和( )。 A.scriptB.bodyC.titleD.link 二、下面哪段javascript能弹出一个提示框?( ) A.document.alert(test) B.window.alert(test) C.document.alert('test ') D.window.alert('test ') 三、当鼠标放在一个链接上的css样式应该( )伪类来定义。 A.a:visitedB.a:linkC.a:hoverD.a:active 四、关于ASP.NET的代码隐藏文件的描述正确的是( )。 A.Web窗体页的程序的逻辑由代码组成,这些代码的创建用于与窗体交互。该文件称作为“代码隐藏”文件,如果用C#创建,该文件将具有“.ascx.cs”扩展名 B.web窗体也是类 C.项目所有的Web窗体页的代码隐藏文件都被编译成项目动态链接库(.dll)文件 D.以上都不正确 五、下列ASP.NET语句( )正确地创建了一个与SQL Server数据库的连接。 A.SqlConnection con1 = new Connection(“Data Source = localhost; Trusted_Connection =Yes; Initial Catalog = myDB”); B.SqlConnection con1 = new SqlConnection(“Data Source = localhost; Trusted_Connection =Yes; Initial Catalog = myDB”); C.SqlConnection con1 = new OleDbConnection(“Data Source = localhost; Trusted_Connection =Yes; Initial Catalog = myDB”); D.SqlConnection con1 = new SqlConnection(Data Source = localhost; Trusted_Connection =Yes; Initial Catalog = myDB); 六、执行一次无返回值的数据删除,必须用到下面哪些对象? ( ) A.SqlConnectionB.SqlDataAdapterC.SqlCommandD.SqlDataReader 七、在ADO.NET,对于Command对象的ExecuteNonQuery()方法和ExecuteReader()方法,下面叙述错误的是( ) A.insert、update、delete等操作的Sql语句主要用ExecuteNonQuery()方法来执行; B.ExecuteNonQuery()方法返回执行Sql语句所影响的行数。 C.Select操作的Sql语句只能由ExecuteReader()方法来执行; D.ExecuteReader()方法返回一个DataReder对象; 八、ASP.NET有多种维护状态的技术,以下哪种是保存在客户端的?( ) A.VIEWSTATEB.SESSIONC.APPLICATIOND.数据CACHE 九、Cookies的默认生命周期有多长? ( ) A.20分钟B.30分钟C. 一天D.随浏览器的关闭而失效 十、int[][] myArray=new int[3][]{ new int[3]{ 5, 6, 2 }, new int[5]{ 6, 9, 7, 8, 3 }, new int[2]{ 3, 2 }}; myArray[2][2]的值是( ) A.9B.2C.6D.越界 十一、要为做了输出缓存的页面实现即时判断用户IP来路,可在以下哪种事件实现? ( ) A.Page.InitB.HttpApplication.BeginRequest C.Page.LoadD.以上都不是 十二、下面哪个SQL语句完全正确( ) A.Select count(*) from (select top 10 * from table order by bb) tb group by cc B.update set bb = bb + 1 from table C.Select count(*) from (select distinct * from table) tb group by cc D.delete * from table 十三、为了实现a.aspx的URL重写,下面哪个正则表达式替换可以实现?( ) A. Regex.Replace(sUrl, @“/(\d+).aspx”, “a.aspx?ID=$0”, RegexOptions.IgnoreCase) B. Regex.Replace(sUrl, @“/(\d+).aspx”, “/a.aspx?ID=$0”, RegexOptions.IgnoreCase) C. Regex.Replace(sUrl, @“/(\d+).aspx”, “a.aspx?ID=$1”, RegexOptions.IgnoreCase) D. Regex.Replace(sUrl, @“/(\d+).aspx”, “/a.aspx?ID=$1”, RegexOptions.IgnoreCase) 十四、下面javascript代码的输出结果是( ) var aa = new Array(1, 2, 4, 5, 3, 6); var c = 0; for (var i = 0; i < aa.length; ++i){ c += aa.pop(); } document.write(c); 提示:Array.pop()函数将数组内最后一个元素移除并返回该元素 A.7 B.14 C.21 D.以上皆不正确 填空题(共4题): 一、C#判断整型变量k是否偶数的语句: 二、有这样的枚举定义:public enum TrainType{ 空调, 快速, 新型, 卧铺 },为实现它的按位组合,你会分别赋予它们什么值?请用逗号按顺序分隔开 三、C#为了防止非本程序集的代码访问,可以用什么关键字修饰类或者类成员? 四、为了将table表内bb(datetime类型)字段的数据按年月降序输出,对应的SQL语句为 选择题答案: 1.B,2.D,3.C,4.BC,5.B,6.AC,7.C,8.A,9.D,10.D,11.B,12.AC,13.D,14.B 填空题答案: 1.(k & 1) == 0 或 k % 2 == 0 2.1,2,4,8(答案不定,看情况) 3.internal 4.select * from table order by year(bb) desc, month(bb) desc 1.new有几种用法 第一种:new Class(); 第二种:覆盖方法 public new XXXX(){} 第三种:new 约束指定泛型类声明的任何类型参数都必须有公共的无参数构造函数。 2.如何把一个array复制到arrayList里 foreach( object o in array )arrayList.Add(o); 3.datagrid.datasouse可以连接什么数据源 [dataset,datatable,dataview] dataset,datatable,dataview , IList 4.概述反射和序列化 反射:程序集包含模块,而模块包含类型,类型又包含成员。反射则提供了封装程序集、模块和类型的对象。您可以使用反射动态地创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型。然后,可以调用类型的方法或访问其字段和属性 序列化:序列化是将对象转换为容易传输的格式的过程。例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象。在另一端,反序列化将从该流重新构造对象。 5.概述o/r mapping 的原理 利用反射,配置 将类于数据库表映射 6.类成员有( )种可访问形式 可访问形式?不懂。 可访问性:public ,protected ,private,internal 7.用sealed修饰的类有什么特点 sealed 修饰符用于防止从所修饰的类派生出其它类。如果一个密封类被指定为其他类的基类,则会发生编译时错误。 密封类不能同时为抽象类。 sealed 修饰符主要用于防止非有意的派生,但是它还能促使某些运行时优化。具体说来,由于密封类永远不会有任何派生类,所以对密封类的实例的虚拟函数成员的调用可以转换为非虚拟调用来处理。 8.列举ADO.NET的五个主要对象,并简单描述 connection,command,dataReader,trans,dataset ... 9.执行下面代码后: String strTemp ="abcdefg 某某某"; Int i System.Text.Encoding.Default.GetBytes(strTemp).Length; Int j = strTemp.Length; 问:i=(14 ) ;j=(11 ) i=(14 ) ;j=(11 ) 文两个字节 10.C#,string str = null 与 string str ="",请尽量用文字说明区别。(要点:说明详细的内存空间分配) string str ="" 分配空间 11.详述.NET里class和struct的异同! class:放在 ? struct放在? struct值传递 类与结构有很多相似之处:结构可以实现接口,并且可以具有与类相同的成员类型。然而,结构在几个重要方面不同于类:结构为值类型而不是引用类型,并且结构不支持继承。结构的值存储在“在堆栈上”或“内联”。细心的程序员有时可以通过聪明地使用结构来增强性能。 12.概述.NET里对 remoting 和 webservice 两项技术的理解和实际的应用。 远程逻辑调用,remoing接口只能用在.net 13.什么是code-behind技术 aspx and cs 14.概述三层结构体系 web/business/dataaccess 15.asp.net如何实现MVC模式,举例说明! web/business/dataaccess ---------------------------------------------------------------------------------------------------------- 1.面向对象的思想主要包括什么? 答:这个题范围太广,不知道说什么. 2.什么是ASP.net的用户控件 答:用户控件就是.ascx扩展名的东西喽,可以拖到不同的页面调用,以节省代码.比如登陆可能在多个页面上有,就可以做成用户控件,但是有一个问题就是用户控件拖到不同级别的目录下后里面的图片等的相对路径会变得不准确,需要自已写方法调整. 3.什么叫应用程序域?什么是受管制的代码?什么是强类型系统?什么是装箱和拆箱?什么是重载?CTS、CLS和CLR分别作何解释? 答:装箱就是把值类型转成引用类型,从MS IL角度看好像是boxing,没记错的话是把值从堆栈转到堆.拆箱相反,重载就是指一个方法名同,参数个数不同,返回值可以相同的方法.CLR是通用语言运行时,其它的不清楚. 4.列举一下你所了解的XML技术及其应用 答:XML可是好东西,保存配置,站与站之间的交流,WEB SERVICE都要用它. 5.值类型和引用类型的区别?写出C#的样例代码。 答:结构是值类型,类是引用类型,所以传结构就是值类型的应用啦,传对象或类就是引用类型的,这个不用多写了吧. 6.ADO.net常用的对象有哪些?分别描述一下。 答:connection command sqladapter dataset datatable dataview等等.写不完了. 7.如何理解委托? 答:据说相当于函数指针,定义了委托就可以在不调用原方法名称的情况下调用那个方法. msdn2005是这样解释的: 委托具有以下特点: 委托类似于 C++ 函数指针,但它是类型安全的。 委托允许将方法作为参数进行传递。 委托可用于定义回调方法。 委托可以链接在一起;例如,可以对一个事件调用多个方法方法不需要与委托签名精确匹配。有关更多信息,请参见协变和逆变。 C# 2.0 版引入了匿名方法的概念,此类方法允许将代码块作为参数传递,以代替单独定义的方法。 8.C#的接口和类有什么异同。 答:这个异同可多了,要说清楚还真不容易. 9.。net读写数据库需要用到哪些类?他们的作用 答:这个类自已可以写的啊,你是指基类吗?那configuration,sqlconnection,sqlcommand等都要用到. 10.UDP连接和TCP连接的异同。 答:前者只管传,不管数据到不到,无须建立连接.后者保证传输的数据准确,须要连结. 11.ASP.net的身份验证方式有哪些?分别是什么原理? 答:form认证,windows集成认证等,原理不清楚. 12.进程和线程分别怎么理解? 答:进程是老子,线程是儿子,没有老子就没有儿子,一个老子可以有多个儿子.一个儿子可以成为别人的儿子,一个老子也可以为别的老子生儿子. 13.什么是code-Behind技术。 答:代码分离,这是个明智的东西,像ASP这样混成一堆很不爽.或者可以理解成HTML代码写在前台,C#代码写在后台.当然前台也有脚本,类的调用等,其实写在一起也是可以的. 14.活动目录的作用。 答:这个不明白.请明白的补充一下. 15..net读写XML的类都归属于哪些命名空间? 答:System.Xml 我自已写的就不一定了,嘿嘿. 16.解释一下UDDI、WSDL的意义及其作用。 答:什么东西? 17.什么是SOAP,有哪些应用。 答:SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境交换信息并执行远程过程调用的协议,是一个基于XML的协议。使用SOAP,不用考虑任何特定的传输协议(最常用的还是HTTP协议),可以允许任何类型的对象或代码,在任何平台上,以任何一直语言相互通信。这种相互通信采用的是XML格式的消息,具体请看:http://playist.blogchina.com/2521621.html 18.如何部署一个ASP.net页面。 答:随便啦,想直接上传就直接上传,想打包成EXE就打包,看个人喜好. 19.如何理解.net的垃圾回收机制。 答:GC?对象创建了总要清除啊,不然内存哪够用?

62,025

社区成员

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

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

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

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