Add records to an Access Database with a Stored Procedure in VB.NET

This article shows how to add records to an Access database with a stored procedure.
  • 2414

This is how I ad records to an access db with a stored procedure.
Hope this helps.

Imports System
Imports System.Data
Imports System.Data.OleDb
Namespace Logs
Public Class LogRec
Public strAgencyID As String
Public
dateLog As Date
Public
strVeNum As String
Public
intBeginMiles As Integer
Public
intEndMiles As Integer
End
Class
Public
Class Logs
Private objConn As New OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= path to Access db with stored procedure named 'spAddLog' ")
Public Sub subAddLogRec(ByVal objLog As LogRec)
Dim intID As Integer
Dim
objReader As OleDbDataReader
Dim objCmd As New OleDbCommand("spAddLog", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@strAgencyID", OleDbType.Char)
objParam.Value = objLog.strAgencyID
objCmd.Parameters.Add(objParam)
objParam = New OleDbParameter("@dateLog", OleDbType.Date)
objParam.Value = objLog.dateLog
objCmd.Parameters.Add(objParam)
objParam = New OleDbParameter("@strVeNum", OleDbType.Char)
objParam.Value = objLog.strVeNum
objCmd.Parameters.Add(objParam)
objParam = New OleDbParameter("@intBeginMiles", OleDbType.integer)
objParam.Value = objLog.intBeginMiles
objCmd.Parameters.Add(objParam)
objParam = New OleDbParameter("@intEndMiles", OleDbType.integer)
objParam.Value = objLog.intEndMiles
objCmd.Parameters.Add(objParam)
Try
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
Catch e As Exception
Throw e
End Try
End
Sub
End
Class
End
Namespace

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.