Flippedbeyond
Well-known member
- Joined
- Dec 19, 2008
- Messages
- 198
- Programming Experience
- 1-3
Hi all,
I consider myself to be a beginner to intermediate programmer, i'm pretty new to working with an access file through vb. This is of low priority since i am getting the results that i want, but i just don't understand why it's working this way. Any explanation would be much appreciated.
I have a MS access 2007 .accdb file that contains a query named addStudentRegistration with the following sql
the code from my function to call this query
Now the issue is that if i call this function and pass in the following
and if i changed the parameter name to something different, it still does the same thing, its as if the parameter names are useless.. i dont understand exactly what is going on, but i figure it should relate to the parameter name that was given in the query from the access file no? i can't seem to get this code to work by using the Parameters.Add and just doing something like Parameters.Add("alumni"), it only works when i use the Parameters.AddWithValue("typename","alumni")
so if the previous code was exchanged with the following, the same results are still given.
It seems to just get the parameters in order and disregards anything i put for the parameter name.. So to be more specific. How exactly should the AddWithValue function from System.Data.OleDb.OleDbParameter be used? And what is the proper way to call a query from a .accdb file with parameters passed in if this method is incorrect?
Thank you, any help is much appreciated
Regards,
-Flippedbeyond
I consider myself to be a beginner to intermediate programmer, i'm pretty new to working with an access file through vb. This is of low priority since i am getting the results that i want, but i just don't understand why it's working this way. Any explanation would be much appreciated.
I have a MS access 2007 .accdb file that contains a query named addStudentRegistration with the following sql
VB.NET:
INSERT INTO Students ( Student_ID, FirstName, LastName, Type_ID )
SELECT Student_ID AS Expr1, firstName AS Expr2, lastName AS Expr3, getID_Type.ID
FROM getID_Type;
the code from my function to call this query
VB.NET:
Protected Function storedProcedure(ByVal procedureName As String, Optional ByVal parameterValues As Dictionary(Of String, String) = Nothing) As Boolean
Dim success As Boolean = False
If connectionFound Then
Dim parameters As String() = parameterValues.Keys.ToArray()
Try
Dim AccessConnection As New System.Data.OleDb.OleDbConnection(connectionString)
AccessConnection.Open()
Dim cmd As New OleDb.OleDbCommand(procedureName, AccessConnection)
cmd.CommandType = CommandType.StoredProcedure
If Not (parameterValues Is Nothing) Then
For Each parameter As String In parameters
cmd.Parameters.AddWithValue(parameter, parameterValues(parameter))
Next
End If
cmd.ExecuteNonQuery()
cmd.Dispose()
AccessConnection.Close()
success = True
Catch ex As Exception
success = False
End Try
End If
Return success
End Function
Now the issue is that if i call this function and pass in the following
VB.NET:
Dim parameters As New Dictionary(Of String, String)
parameters.Add("typeName", "alumni")
parameters.Add("student_id", "343117")
parameters.Add("firstName", "wjwo")
parameters.Add("lastName", "lool")
MyBase.storedProcedure("addStudentRegistration", parameters)
and if i changed the parameter name to something different, it still does the same thing, its as if the parameter names are useless.. i dont understand exactly what is going on, but i figure it should relate to the parameter name that was given in the query from the access file no? i can't seem to get this code to work by using the Parameters.Add and just doing something like Parameters.Add("alumni"), it only works when i use the Parameters.AddWithValue("typename","alumni")
so if the previous code was exchanged with the following, the same results are still given.
VB.NET:
Dim parameters As New Dictionary(Of String, String)
parameters.Add("tye", "alumni")
parameters.Add("std", "343117")
parameters.Add("fiNe", "wjwo")
parameters.Add("lase", "lool")
MyBase.storedProcedure("addStudentRegistration", parameters)
It seems to just get the parameters in order and disregards anything i put for the parameter name.. So to be more specific. How exactly should the AddWithValue function from System.Data.OleDb.OleDbParameter be used? And what is the proper way to call a query from a .accdb file with parameters passed in if this method is incorrect?
Thank you, any help is much appreciated
Regards,
-Flippedbeyond
Last edited: