private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); txtID.Text = txtID.Text.Trim(); txtName.Text = txtName.Text.Trim(); if (txtID.Text == "" && txtName.Text == "") { dt = SQLHelper.ExecuteQuery("select id as '图书证号',ISBN,sName as '姓名',name as '书名',date as '借书日期',residue as '剩余日期' from Books_Borrow"); } else if (txtID.Text != "" && txtName.Text == "") { dt = SQLHelper.ExecuteQuery("select id as '图书证号',ISBN,sName as '姓名',name as '书名',date as '借书日期',residue as '剩余日期' from Books_Borrow where id=@id", new SqlParameter("@id", txtID.Text)); } else if (txtID.Text == "" && txtName.Text != "") { dt = SQLHelper.ExecuteQuery("select id as '图书证号',ISBN,sName as '姓名',name as '书名',date as '借书日期',residue as '剩余日期' from Books_Borrow where sName=@name", new SqlParameter("@name", txtName.Text)); } else if (txtID.Text != "" && txtName.Text != "") { dt = SQLHelper.ExecuteQuery("select id as '图书证号',ISBN,sName as '姓名',name as '书名',date as '借书日期',residue as '剩余日期' from Books_Borrow where sName=@name and id=@id", new SqlParameter("@name", txtName.Text), new SqlParameter("@id", txtID.Text)); } f.SetDT(dt, DataType.Borrow); this.Close(); }
private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); txtID.Text = txtID.Text.Trim(); txtName.Text = txtName.Text.Trim(); if (txtID.Text == "" && txtName.Text == "") { dt = SQLHelper.ExecuteQuery("select sID as '图书证号',sName as '姓名',sDepartment as '学院',sSpecialty as '专业' from Student"); } else if (txtID.Text != "" && txtName.Text == "") { dt = SQLHelper.ExecuteQuery("select sID as '图书证号',sName as '姓名',sDepartment as '学院',sSpecialty as '专业' from Student where sID=@id", new SqlParameter("@id", txtID.Text)); } else if (txtID.Text == "" && txtName.Text != "") { dt = SQLHelper.ExecuteQuery("select sID as '图书证号',sName as '姓名',sDepartment as '学院',sSpecialty as '专业' from Student where sName=@name", new SqlParameter("@name", txtName.Text)); } else if (txtID.Text != "" && txtName.Text != "") { dt = SQLHelper.ExecuteQuery("select sID as '图书证号',sName as '姓名',sDepartment as '学院',sSpecialty as '专业' from Student where sName=@name and sID=@id", new SqlParameter("@name", txtName.Text), new SqlParameter("@id", txtID.Text)); } f.SetDT(dt, DataType.Students); this.Close(); }
private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); txtName.Text = txtName.Text.Trim(); if (txtName.Text == "") { string strSql = "select bISBN as 'ISBN',bName as '书名',bPlace as '位置',bNumber as '剩余数量' from Books"; dt = SQLHelper.ExecuteQuery(strSql); } else { string strSql = "select bISBN as 'ISBN',bName as '书名',bPlace as '位置',bNumber as '剩余数量' from Books where bName=@name"; dt = SQLHelper.ExecuteQuery(strSql, new System.Data.SqlClient.SqlParameter("@name", txtName.Text)); } f.SetDT(dt, DataType.Books); this.Close(); }