private void btnFind_Click(object sender, EventArgs e) { WFilter wf = new WFilter(1, "CustName", true); wf.tableName = "T_CustomerInf"; //表名 wf.strSql = "select CustID as 客户编号, CustName as 客户名称, CustType as 类别,City as 城市地区,communicateAddr as 通信地址, CredDegree as 信用等级,T_CustomerImp.importance as 客户重要度 " + " from T_CustomerInf left join T_CustomerImp " + " on T_CustomerInf.ImportanceDegreeId= T_CustomerImp.Iid"; wf.s_items.Add("客户编号,CustID,C"); wf.s_items.Add("客户名称,CustName,C"); wf.s_items.Add("类别,CustType,C"); wf.s_items.Add("城市地区,City,C"); wf.s_items.Add("重要度,importance,C"); wf.ShowDialog(); if (wf.DialogResult == DialogResult.OK) { //插入 List <string> sqls = new List <string>(); DBUtil dbUtil = new DBUtil(); string custId = this.custid; foreach (string CustName in wf.Return_Items) { string parentcustId = dbUtil.Get_Single_val("T_CustomerInf", "CustID", "CustName", CustName.Trim()); if (parentcustId == "") { return; } //插入前判断 string strSqlSel = "select * from T_Customer_Rela where CustID='{0}' and ParentID='{1}'"; strSqlSel = string.Format(strSqlSel, custId, parentcustId); bool isExit = dbUtil.yn_exist_data(strSqlSel); if (isExit == true) { return; } string strSql = "insert into T_Customer_Rela(CustID,ParentID) values('{0}','{1}')"; strSql = string.Format(strSql, custId, parentcustId); sqls.Add(strSql); } (new SqlDBConnect()).Exec_Tansaction(sqls); InitDataGridView(); } }