帮忙看下DataGridView数据库模糊查询的怎么写方法。一个txt和一个Button。要求把查询的结果加载到dgv中
publicvoidloadData(stringcondition){DBSQLsql=newDBSQL();try{if(dgvDepartment.Rows.Cou...
public void loadData(string condition)
{
DBSQL sql = new DBSQL();
try
{
if (dgvDepartment.Rows.Count > 0)
dgvDepartment.Rows.Clear();
System.Data.DataTable dt = new System.Data.DataTable();
if (condition.Trim() == "")
{
dt = sql.dbToDS("select dNumber,dName,dPhone,dMemo,dHeader from [Department]", "temp").Tables["temp"];
for (int i = 0; i < dt.Rows.Count; i++)
{
i = dgvDepartment.Rows.Add();
dgvDepartment.Rows[i].Cells["colDpNumber"].Value = dt.Rows[i]["dNumber"].ToString().Trim();
// ........
System.Data.DataTable uN = sql.dbToDS("select uName from vw_TeacherUsers where tNumber='" + dt.Rows[i]["dHeader"].ToString().Trim() + "'", "temp").Tables["temp"];
if (uN.Rows.Count>0)
dgvDepartment.Rows[i].Cells["colDpHeader"].Value = uN.Rows[0]["uName"].ToString().Trim();
else
dgvDepartment.Rows[i].Cells["colDpHeader"].Value = "";
}
}
else
{......} 展开
{
DBSQL sql = new DBSQL();
try
{
if (dgvDepartment.Rows.Count > 0)
dgvDepartment.Rows.Clear();
System.Data.DataTable dt = new System.Data.DataTable();
if (condition.Trim() == "")
{
dt = sql.dbToDS("select dNumber,dName,dPhone,dMemo,dHeader from [Department]", "temp").Tables["temp"];
for (int i = 0; i < dt.Rows.Count; i++)
{
i = dgvDepartment.Rows.Add();
dgvDepartment.Rows[i].Cells["colDpNumber"].Value = dt.Rows[i]["dNumber"].ToString().Trim();
// ........
System.Data.DataTable uN = sql.dbToDS("select uName from vw_TeacherUsers where tNumber='" + dt.Rows[i]["dHeader"].ToString().Trim() + "'", "temp").Tables["temp"];
if (uN.Rows.Count>0)
dgvDepartment.Rows[i].Cells["colDpHeader"].Value = uN.Rows[0]["uName"].ToString().Trim();
else
dgvDepartment.Rows[i].Cells["colDpHeader"].Value = "";
}
}
else
{......} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询