?? query.cs
字號:
//
// 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.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);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -