ARTICLE

How do I add records to an Access Database with a Stored Procedure?

Posted by Praveen Kumar Articles | Visual Basic 2010 November 16, 2004
This article shows how to add records to an Access database with a stored procedure.
 
Reader Level:

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

share this article :
post comment
 
Nevron Diagram
Become a Sponsor
MOST LIKED ARTICLE
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor