Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

How do I use a sql statement with If Else statement in my application?

What I have tried:

I have my sql connection open to my database. I have the sql statment. I'm just not sure how to combine that with my if end if statement.

Here is my sql clause:
sqlstmt = "SELECT Color_ID FROM Crayon_LOT WHERE Color_ID = #ADD8E6"

And how I think I should be verifying that a unique S/N is a specific color. If it is, start a countdown.

If Textbox1.ColorID = #ADD8E6" Then
    countdown = TimeSpan.FromSeconds(5)
            endTime = DateTime.Now.Add(countdown)
End If

I am not sure on how to exactly use the sql within
Updated 28-Feb-23 7:49am
Maciej Los 28-Feb-23 11:12am    
Sorry, your question is not clear. Please, be more specific and provide sample data and expected output. Use "Improve question" widget (on the rigth-bottom corner).
newVBM3 28-Feb-23 12:16pm    
I used the Improve question option. Is it better?
CHill60 28-Feb-23 12:18pm    
I'm sorry it's still not clear. What does SQL have to do with the colour of the Texbox? I think you need to show a little bit more of your code to give us context. Include the sql connection (but not any logon details) so we can determine how you are connecting
newVBM3 28-Feb-23 13:31pm    
For ex. The table in SQL has a column Color_ID and Crayon_SN. The table is called Crayon_Lot. When I enter a specific crayon sn in the textbox, I want the program to scan through the specific table, look at the sn and see what is the color ID for that sn, then start a countdown time.

Here is sql connection:
Public Const CR_Connect "Data Source=MyServerName;Initial Catalog=MyDatabaseName;User ID=MyUserName;Password=MySuperSecretPassword"

Then I am setting up Dim for sql call out.

strSqlConnection = CR_Connect
objcn = New SqlConnection(strSqlConnection)

sqlstmt = "SELECT Color_ID FROM Crayon_LOT WHERE Color_ID = #ADD8E6"

Hope that makes it a bit better.

1 solution

Share this answer
Maciej Los 28-Feb-23 15:14pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900