且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C#中建立复杂的、灵活的SQL查询/命令

更新时间:2022-09-11 13:55:20


string statement = "SELECT TOP " + maxRecords + " * FROM Customers ";    string whereConcatenator = "WHERE ";    if (companyNameTextBox.Text.Length > 0)    {     statement += whereConcatenator;     statement += "CompanyName like "" + companyNameTextBox.Text + "%" ";     whereConcatenator = "AND ";    }    if (cityTextBox.Text.Length > 0)    {     statement += whereConcatenator;     statement += "City like "" + cityTextBox.Text + "%" ";     whereConcatenator = "AND ";    }    if (countryComboBox.SelectedItem != null)    {     statement += whereConcatenator;     statement += "Country = "" + countryComboBox.SelectedItem + "" ";     whereConcatenator = "AND ";    }    本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/archive/2010/03/26/1697070.html,如需转载请自行联系原作者