Hi guys,
I have been palying around with an SQl statement this afternoon, which works outside of my VB.NET application in Management Studio but will not work in the application.
Here is the code I am using:
When I run this code I get the Data type mismatch in criteria expression Exception. I know this is because of the ' quotes I am using around the todaysDate variable. So I have taken them out and am using the following instead:
This, although a valid SQL statement, like the previous one, returns no records to be used in my OleDb.OleDbDataAdapter, testDa.
Can anyone see why it is not returning the record that it should? When I run the SQL statement in Management Studio I get the record back, but not with the statement in my code.
Also, I was using a simpler statement earlier:
This statement worked perfectly, returning the tests that had todays date. But when I tried using
in my second statement, I got the Data type mismatch in criteria expression Exception. This makes no sense. Why would it let me use it in the first statement, but not the second?
Also, testSql is a String, as you have to pass the sql statement as a string to the data adapter. There may be problems arising from this.
Can anyone tell me how I can fix this? Thanks for your help
I have been palying around with an SQl statement this afternoon, which works outside of my VB.NET application in Management Studio but will not work in the application.
Here is the code I am using:
VB.NET:
[SIZE="2"]testSql = "SELECT TestDetails.[TestID], TestDetails.[SubjectArea], TestDetails.[TestDate] FROM TestDetails WHERE TestDetails.[TestDate] = '" + todaysDate + "' AND TestDetails.[TestID] NOT IN (SELECT TestTakenDetails.[TestID] FROM TestTakenDetails WHERE TestTakenDetails.[PupilID] = " + pupilID.ToString + ")"
testDa = New OleDb.OleDbDataAdapter(testSql, getTestConnect)
' Fill dataset with test information
testDa.Fill(testDs, "currentTest")
' Initialise maxQuestions integer
maxTests = testDs.Tables("currentTest").Rows.Count[/SIZE]
When I run this code I get the Data type mismatch in criteria expression Exception. I know this is because of the ' quotes I am using around the todaysDate variable. So I have taken them out and am using the following instead:
VB.NET:
[SIZE="2"]WHERE TestDetails.[TestDate] = " + todaysDate.ToString + " AND TestDetails.[TestID][/SIZE]
This, although a valid SQL statement, like the previous one, returns no records to be used in my OleDb.OleDbDataAdapter, testDa.
Can anyone see why it is not returning the record that it should? When I run the SQL statement in Management Studio I get the record back, but not with the statement in my code.
Also, I was using a simpler statement earlier:
VB.NET:
[SIZE="2"]testSql = "SELECT TestDetails.[TestID], TestDetails.[SubjectArea], TestDetails.[TestDate] FROM TestDetails WHERE TestDetails.[TestDate] = '" + todaysDate + "'"[/SIZE]
This statement worked perfectly, returning the tests that had todays date. But when I tried using
VB.NET:
WHERE TestDetails.[TestDate] = '" + todaysDate + "'"
Also, testSql is a String, as you have to pass the sql statement as a string to the data adapter. There may be problems arising from this.
Can anyone tell me how I can fix this? Thanks for your help