我在textboxes
中有21个checkboxes
和25个winform
,我希望能够输入这些textboxes
并检查checkboxes
并拥有执行语句时返回的相应记录。此时,只要我在where子句中引用了没有checkboxes
的select语句,我就可以通过任何textbox
进行搜索并正常返回我的记录,但是当我通过{{1}添加搜索时除了已经选中checkbox
的记录之外,不会返回任何记录。因此,如果我在checkboxes
中输入任何内容并且未检查textboxes
,我仍会收到未找到记录的消息。
checkbox
然而,即使我没有在where子句中包含复选框,我仍然得到{
con.Open();
string str = "select * from engineering where (JobNumber like '%' + @search + '%' AND DateOrdered
like '%' + @search1 + '%' AND Title like '%' + @search2 + '%' AND PhysicalAddressComplete like
'%' + @search3 + '%' AND County like '%' + @search4 + '%' AND Client like '%' + @search5 + '%'
AND Contact like '%' + @search6 + '%' AND ContactTitle like '%' + @search7 + '%' AND
MailingAddressComplete like '%' + @search8 + '%' AND BusinessPhone like '%' + @search9 + '%'
AND CellPhone like '%' + @search10 + '%' AND Email like '%' + @search11 + '%' AND OpenStatus
like '%' + @search12 + '%' AND CloseStatus like '%' + @search13 + '%' AND Cabinet
like '%' + @search14 + '%' AND Roll like '%' + @search15 + '%' AND Drawer like '%' + @search16 + '%'
AND ConstructionDrawings like '%' + @search17 + '%' AND Fee like '%' + @search18 + '%' AND
ConstructionCost like '%' + @search19 + '%' AND ProjectDescription like '%' + @search20 + '%'
AND DesignBuild like " + DesignBuild + " )";
SqlCommand xp = new SqlCommand(str, con);
xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = txtProjectNumber.Text;
xp.Parameters.Add("@search1", SqlDbType.NVarChar).Value = txtDateOrdered.Text;
xp.Parameters.Add("@search2", SqlDbType.NVarChar).Value = txtProjectName.Text;
xp.Parameters.Add("@search3", SqlDbType.NVarChar).Value = txtProjectAddress.Text;
xp.Parameters.Add("@search4", SqlDbType.NVarChar).Value = txtCounty.Text;
xp.Parameters.Add("@search5", SqlDbType.NVarChar).Value = txtClient.Text;
xp.Parameters.Add("@search6", SqlDbType.NVarChar).Value = txtClientContact.Text;
xp.Parameters.Add("@search7", SqlDbType.NVarChar).Value = txtContactTitle.Text;
xp.Parameters.Add("@search8", SqlDbType.NVarChar).Value = txtBillingAddress.Text;
xp.Parameters.Add("@search9", SqlDbType.NVarChar).Value = txtBusinessPhone.Text;
xp.Parameters.Add("@search10", SqlDbType.NVarChar).Value = txtCellPhone.Text;
xp.Parameters.Add("@search11", SqlDbType.NVarChar).Value = txtEmail.Text;
xp.Parameters.Add("@search12", SqlDbType.NVarChar).Value = txtOpenStatus.Text;
xp.Parameters.Add("@search13", SqlDbType.NVarChar).Value = txtCloseStatus.Text;
xp.Parameters.Add("@search14", SqlDbType.NVarChar).Value = txtCabinet.Text;
xp.Parameters.Add("@search15", SqlDbType.NVarChar).Value = txtRoll.Text;
xp.Parameters.Add("@search16", SqlDbType.NVarChar).Value = txtDrawer.Text;
xp.Parameters.Add("@search17", SqlDbType.NVarChar).Value = txtDrawings.Text;
xp.Parameters.Add("@search18", SqlDbType.NVarChar).Value = txtFee.Text;
xp.Parameters.Add("@search19", SqlDbType.NVarChar).Value = txtCost.Text;
xp.Parameters.Add("@search20", SqlDbType.NVarChar).Value = txtProjectDescription.Text;
try
{
da = new SqlDataAdapter();
da.SelectCommand = xp;
da.Fill(ss);
Showdata(pos);
if (ss.Rows.Count >0)
{
this.chkEducational.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Education"] == 1);
this.chkDesign.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["DesignBuild"] == 1);
this.chkMedical.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Medical"] == 1);
this.chkReligious.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Religious"] == 1);
this.chkMulti.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["MultiFamily"] == 1);
this.chkStudent.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Student"] == 1);
this.chkAssisted.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Assisted"] == 1);
this.chkSingleFamily.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Single"] == 1);
this.chkBridge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Bridge"] == 1);
this.chkIntersection.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Intersection"] == 1);
this.chkRoadway.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Roadway"] == 1);
this.chkTransOther.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["TransportationOther"] == 1);
this.chkRetailSmall.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["SmallRetail"] == 1);
this.chkRetailLarge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["LargeRetail"] == 1);
this.chkParks.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Parks"] == 1);
this.chkIndustrial.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Industrial"] == 1);
this.chkUtility.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Utility"] == 1);
this.chkGCSmall.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["GCSmall"] == 1);
this.chkGCLarge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["GCLarge"] == 1);
this.chkOffice.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Office"] == 1);
this.chkOther.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Other"] == 1);
this.chkMunicipal.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Municipal"] == 1);
this.chkPrivate.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Privates"] == 1);
this.chkInstitutional.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Institutional"] == 1);
this.chkMilitary.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Military"] == 1);
}
}
catch
{
MessageBox.Show("No Record Found");
}
con.Close();
}
,然后一旦我点击该消息框,我的结果就会显示出来。任何有关这两个问题的帮助都会很棒。
答案 0 :(得分:0)
您是否尝试在检查if (ss.Rows.Count >0)
this.chkEducational.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Education"] == 1);
this.chkDesign.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["DesignBuild"] == 1);
this.chkMedical.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Medical"] == 1);
this.chkReligious.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Religious"] == 1);
this.chkMulti.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["MultiFamily"] == 1);
this.chkStudent.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Student"] == 1);
this.chkAssisted.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Assisted"] == 1);
this.chkSingleFamily.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Single"] == 1);
this.chkBridge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Bridge"] == 1);
this.chkIntersection.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Intersection"] == 1);
this.chkRoadway.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Roadway"] == 1);
this.chkTransOther.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["TransportationOther"] == 1);
this.chkRetailSmall.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["SmallRetail"] == 1);
this.chkRetailLarge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["LargeRetail"] == 1);
this.chkParks.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Parks"] == 1);
this.chkIndustrial.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Industrial"] == 1);
this.chkUtility.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Utility"] == 1);
this.chkGCSmall.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["GCSmall"] == 1);
this.chkGCLarge.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["GCLarge"] == 1);
this.chkOffice.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Office"] == 1);
this.chkOther.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Other"] == 1);
this.chkMunicipal.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Municipal"] == 1);
this.chkPrivate.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Privates"] == 1);
this.chkInstitutional.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Institutional"] == 1);
this.chkMilitary.Checked = ((int)ss.AsEnumerable().FirstOrDefault()["Military"] == 1);
你的代码在某个地方破坏了,这就是它显示错误的原因。
您能否分享屏幕截图以及数据集中ss