[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

How to write an IF clause within a C# application for a Windows platform using VS2005?

I am developing a C# application using VS2005 in a Windows platorm with SQL Server as the back end database.

In the following snippet of code, I wish to evaluate a string named "cycle"

If cycle = "fall" then the FROM clause of the SQL statement should state:
FROM [tblFlLNMod$]", conn);

Else                         the FROM clause of the SQL statement should state:
FROM [tblSpLNMod$",conn);

How would you perform the IF test for the 2 forms of the SQL ... FROM clause
in the following context?

========================================

DataTable sourceData = new DataTable();

            using (OleDbConnection conn = new OleDbConnection(sourceConnString))
            {
                conn.Open();

                OleDbCommand command = new OleDbCommand(

                         @"SELECT [CPS 1st First Name],
                                  [CPS 1st Mid],
                                  [CPS 1st Last Name],
                                  [CPS 2nd First Name],
                                  [CPS 2nd Mid],
                                  [CPS 2nd Last Name],
                                  [CPS Address 1],
                                  [CPS Address 2],
                                  [CPS City],
                                  [CPS State],
                                  [CPS Zip],
                                  [CPS SSN/Tax ID],
                                  [CPS Account Number],
                                  [FA Number],
                                  [CPS Date Of Birth],
                                  [LEXIS NEXIS 1st First Name],
                                  [LEXIS NEXIS 1st Mid],
                                  [LEXIS NEXIS 1st Last Name],
                                  [LEXIS NEXIS Address],
                                  [LEXIS NEXIS City],
                                  [LEXIS NEXIS State],
                                  [LEXIS NEXIS Zip],
                                  [LEXIS NEXIS Phone],
                                  [Escheat Y/N]            
                           FROM [tblSpLNMod$]", conn);

                OleDbDataAdapter adapter = new OleDbDataAdapter(command);

                adapter.Fill(sourceData);

                conn.Close();
0
zimmer9
Asked:
zimmer9
1 Solution
 
Anurag ThakurCommented:
do like this

OleDbCommand command = new OleDbCommand(
       "SELECT
          [CPS 1st First Name],
              [CPS 1st Mid],
          [CPS 1st Last Name],
          [CPS 2nd First Name],
          [CPS 2nd Mid],
          [CPS 2nd Last Name],
          [CPS Address 1],
          [CPS Address 2],
          [CPS City],
          [CPS State],
          [CPS Zip],
          [CPS SSN/Tax ID],
          [CPS Account Number],
          [FA Number],
          [CPS Date Of Birth],
          [LEXIS NEXIS 1st First Name],
          [LEXIS NEXIS 1st Mid],
          [LEXIS NEXIS 1st Last Name],
          [LEXIS NEXIS Address],
          [LEXIS NEXIS City],
          [LEXIS NEXIS State],
          [LEXIS NEXIS Zip],
          [LEXIS NEXIS Phone],
          [Escheat Y/N]  
         FROM "
+ cycle == "fall" ? "[tblFlLNMod$]" : "[tblSpLNMod$]" , conn);
0
 
AyyappanRdknCommented:
DataTable sourceData = new DataTable();

            using (OleDbConnection conn = new OleDbConnection(sourceConnString))
            {
                conn.Open();

                OleDbCommand command = new OleDbCommand(

                         @"SELECT [CPS 1st First Name],
                                  [CPS 1st Mid],
                                  [CPS 1st Last Name],
                                  [CPS 2nd First Name],
                                  [CPS 2nd Mid],
                                  [CPS 2nd Last Name],
                                  [CPS Address 1],
                                  [CPS Address 2],
                                  [CPS City],
                                  [CPS State],
                                  [CPS Zip],
                                  [CPS SSN/Tax ID],
                                  [CPS Account Number],
                                  [FA Number],
                                  [CPS Date Of Birth],
                                  [LEXIS NEXIS 1st First Name],
                                  [LEXIS NEXIS 1st Mid],
                                  [LEXIS NEXIS 1st Last Name],
                                  [LEXIS NEXIS Address],
                                  [LEXIS NEXIS City],
                                  [LEXIS NEXIS State],
                                  [LEXIS NEXIS Zip],
                                  [LEXIS NEXIS Phone],
                                  [Escheat Y/N]            
                           FROM" + cycle == "fall" ? "[tblFlLNMod$]" : "[tblSpLNMod$]" , conn);

                OleDbDataAdapter adapter = new OleDbDataAdapter(command);

                adapter.Fill(sourceData);

                conn.Close();
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now