We help IT Professionals succeed at work.
Get Started

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

zimmer9
zimmer9 asked
on
343 Views
Last Modified: 2012-08-17
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();
Comment
Watch Question
Technical Manager
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE