您的位置:首页 > 数据库

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

2010-03-26 15:34 375 查看
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 ";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: