⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query.cs

📁 visualc#+sql图书出租管理系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
			// sqlSelectCommand4
			// 
			this.sqlSelectCommand4.CommandText = "SELECT ReaderID, ReaderName, ReaderPhoneNo, BookID, BookName, BookWriter, BorrowD" +
				"ate, ReturnDate FROM Borrow";
			this.sqlSelectCommand4.Connection = this.sqlConnection1;
			// 
			// objDataSetQuery
			// 
			this.objDataSetQuery.DataSetName = "DataSetQuery";
			this.objDataSetQuery.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// Query
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.LightGray;
			this.ClientSize = new System.Drawing.Size(536, 373);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnQuery);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnClear);
			this.Controls.Add(this.dataGrid1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Query";
			this.Text = "综合查询";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.objDataSetQuery)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		public void ErrorHandle(System.Exception E)
		{
			MessageBox.Show(E.ToString());
		}		


		private void LoadDataSet()
		{
			DataSetQuery objDataSetTemp=new DataSetQuery();
			try
			{
				this.FillDataSet(objDataSetTemp);

			}
			catch (System.Exception E) 
			{
				// 在此处添加错误处理代码。
				this.ErrorHandle(E);
			}
			try
			{
				this.objDataSetQuery.Clear();
				this.objDataSetQuery.Merge(objDataSetTemp);
			}
			catch(System.Exception E) 
			{
				// 在此处添加错误处理代码。
				this.ErrorHandle(E);
			}
			
		}
		
		private void FillDataSet(DataSetQuery dataset)
		{
			dataset.EnforceConstraints=false;
			try
			{
				this.sqlConnection1.Open();
				this.sqlDataAdapterReader.Fill(dataset);
				this.sqlDataAdapterBook.Fill(dataset);					
				this.sqlDataAdapterPublish.Fill(dataset);
				this.sqlDataAdapterBorrow.Fill(dataset);

			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
		
			finally
			{
				dataset.EnforceConstraints=true;
				this.sqlConnection1.Close();
			}
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void comboDataTable_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string strTable=this.comboDataTable.SelectedItem.ToString();
			if(strTable=="") return;   
			this.comboDataItem.Text="";
			this.comboCondition.Text="";			
			this.textValue.Clear();
			string mySelectQuery="select * from "+strTable;
			SqlCommand myCommand=new SqlCommand(mySelectQuery,this.sqlConnection1);
			if(this.sqlConnection1.State==ConnectionState.Closed) this.sqlConnection1.Open();
			this.comboDataItem.Items.Clear();
			SqlDataReader myReader=myCommand.ExecuteReader();
			for(int i=0;i<myReader.FieldCount;i++)
			{
				this.comboDataItem.Items.Add(myReader.GetName(i).ToString());
			}
			myReader.Close();
			this.sqlConnection1.Close();			
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			this.comboDataTable.Text="";
			this.comboDataItem.Text="";
			this.comboCondition.Text="";
			this.textValue.Text="";

		}

		private void btnQuery_Click(object sender, System.EventArgs e)
		{
			string conValue = this.textValue.Text;//指定的条件值
			SqlString="select * from "+this.comboDataTable.Text;
			if ((this.comboCondition.Text == "Like") && (this.textValue.Text != ""))
				conValue = "%"+this.textValue.Text+"%";
			if ((this.comboDataItem.Text != "") && (this.comboCondition.Text != "") && (this.textValue.Text != ""))
				SqlString=SqlString+" where "+this.comboDataItem.Text+" "+this.comboCondition.Text+" '"+conValue+"'";
			switch(this.comboDataTable.SelectedIndex)
			{
				case 0:
					this.sqlSelectCommand1.CommandText=SqlString;
					break;
				case 1:
					this.sqlSelectCommand2.CommandText=SqlString;
					break;
				case 2:
					this.sqlSelectCommand3.CommandText=SqlString;
					break;
				case 3:
					this.sqlSelectCommand4.CommandText=SqlString;
					break;
			}
			try
			{
				this.LoadDataSet();
				this.dataGrid1.DataSource=this.objDataSetQuery;
				this.dataGrid1.DataMember=this.comboDataTable.Text.Trim();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -