黄聪:在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 ";
}
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 ";
}
相关文章推荐
- 在C#中建立复杂的、灵活的SQL查询/命令
- 在C#中建立复杂的、灵活的SQL查询/命令
- 在C#中建立复杂的、灵活的SQL查询/命令
- 在C#中建立复杂的、灵活的SQL查询/命令
- util-C# 复杂条件查询(sql 复杂条件查询)查询解决方案
- SQL入门 13 建立复杂的数据库查询
- C#连接SQL多条件复杂查询
- sql 入门经典(第五版) Ryan Stephens 学习笔记 第四部分:建立复杂的数据库查询/
- SQL复杂查询(子查询)
- JPA 原生态SQL 的复杂查询(多表Join)《转载》
- c# 经验谈:巧用Expression表达式 解决类似于sql中 select in 的查询(适合于中小型项目)
- C#执行.sql文件中命令
- 复杂 SQL 查询跑不动?DRDS 只读实例来解决!
- SQL复杂查询练习
- C#参数化SQL查询
- 如何编写复杂的多表查询SQL
- 教学思路SQL之入门习题《学员成绩》 三、多表复杂子查询
- C#与SQL命令中单引号字符串的不同效果
- ORACLE SQLPLUS常用命令及查询
- sql将查询结果建立为新表