0

I am writing a program that pulls data from a SQL table connected to an Access database and then populates a DataGridView on a Windows form.

I am wondering if there is a way in the select statement to set parameters around the data I am pulling such as, if I select a column and the data is 1 or 0, the DataGridView can display 1 as yes and 0 as no.

I have tried adjusting the select statement and writing cell formatting functions but nothing seems to be working.

For example:

da = New OleDbDataAdapter("select IA, CASE 1 return 'Yes' case else return 'NO' FROM dbo_tblPLOps_Data WHERE LANID= '" & txtRepID.Text & "' and date >= '" & DateTimePicker1.Text & "' and date <= '" & DateTimePicker2.Text & "'",    newScoreConn)

I tried this too:

da = New OleDbDataAdapter("select IA IF (IA = 1, 'yes', 'no')FROM dbo_tblPLOps_Data WHERE LANID= '" & txtRepID.Text & "' and date >= '" & DateTimePicker1.Text & "' and date <= '" & DateTimePicker2.Text & "'",    newScoreConn)

I am able to adjust the pull and change the DataGridView column header:

da = New OleDbDataAdapter("select IA as [Info Accuracy] FROM dbo_tblPLOps_Data WHERE LANID= '" & txtRepID.Text & "' and date >= '" & DateTimePicker1.Text & "' and date <= '" & DateTimePicker2.Text & "'",    newScoreConn)
2
  • This might be helpful: stackoverflow.com/questions/1283894/… Commented Jun 9, 2017 at 16:52
  • You aren't using parameters. You should. It would prevent sql injection and formatting errors. Commented Jun 12, 2017 at 20:51

1 Answer 1

0

I was able to adjust the syntax of the select statement and get what I was looking for:

IIF(IA = 5, 'yes','no') 

I knew it had to be some variation of an Access IF statement but was having a hard time getting the syntax to display correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.