C
Chris
Hello.
Following SQL-statement works directly in Access
SELECT * FROM Users_ as U, Courses as C
WHERE (U.course_id = @course_id or @course_id is null)
AND U.Course_id = C.Course_id
Now, I'm trying to execute the Sql-statement from an AS.NET
application
It works as long as I don't specify null values for course_id.
When I do, using the following:
Dim cmdString As String = _
String.Format("SELECT * FROM Users_ as U, Courses as C " + _
"WHERE (U.course_id = @course_id or @course_id is
null) " + _
"AND U.Course_id = C.Course_id ")
Dim dbCommand As New OleDbCommand()
dbCommand.CommandText = cmdString
dbCommand.Connection = _dbConnection
Dim dataAdapt As New OleDbDataAdapter()
dataAdapt.SelectCommand = dbCommand
' for testing purposes
course_id = 0
Dim dbParam_CourseID As New OleDbParameter
dbParam_CourseID.ParameterName = "@course_id"
dbParam_CourseID.IsNullable = True
dbParam_CourseID.SourceColumnNullMapping = True
dbParam_CourseID.Value = IIf(course_id = 0, Nothing, course_id)
'passing null
dbCommand.Parameters.Add(dbParam_CourseID)
Dim objDataSet As New DataSet()
dataAdapt.Fill(objDataSet)
I get an error: "Parameter @course_id has no default value."
In access I explicitly specified 'Null' as default value for field
'course_id' but I still get the error
How to solve this?
thank you
Chris
Following SQL-statement works directly in Access
SELECT * FROM Users_ as U, Courses as C
WHERE (U.course_id = @course_id or @course_id is null)
AND U.Course_id = C.Course_id
Now, I'm trying to execute the Sql-statement from an AS.NET
application
It works as long as I don't specify null values for course_id.
When I do, using the following:
Dim cmdString As String = _
String.Format("SELECT * FROM Users_ as U, Courses as C " + _
"WHERE (U.course_id = @course_id or @course_id is
null) " + _
"AND U.Course_id = C.Course_id ")
Dim dbCommand As New OleDbCommand()
dbCommand.CommandText = cmdString
dbCommand.Connection = _dbConnection
Dim dataAdapt As New OleDbDataAdapter()
dataAdapt.SelectCommand = dbCommand
' for testing purposes
course_id = 0
Dim dbParam_CourseID As New OleDbParameter
dbParam_CourseID.ParameterName = "@course_id"
dbParam_CourseID.IsNullable = True
dbParam_CourseID.SourceColumnNullMapping = True
dbParam_CourseID.Value = IIf(course_id = 0, Nothing, course_id)
'passing null
dbCommand.Parameters.Add(dbParam_CourseID)
Dim objDataSet As New DataSet()
dataAdapt.Fill(objDataSet)
I get an error: "Parameter @course_id has no default value."
In access I explicitly specified 'Null' as default value for field
'course_id' but I still get the error
How to solve this?
thank you
Chris