NK-Inc.com
PDF, Programming & Design Tutorials

PDF, Programming & Design Tutorials

PDF, Programming & Design Tutorials for Applications

Tags: , | Categories: PDF Programming Posted by NicK on 4/26/2010 3:36 AM | Comments (0)
This method demonstrates how to save a MS Access database record from a PDF form submission using FDF Toolkit .net and VB.net.
Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Partial Public Class save_pdf_form_submission_to_database
    Inherits System.Web.UI.Page

    Private URLPath As String = ""
    Private cFDFDoc As New FDFApp.FDFDoc_Class
    Private cFDFApp As New FDFApp.FDFApp_Class
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cFDFDoc = cFDFApp.FDFOpenFromStream(Request.InputStream, True, True)
        Try
	  Save_New_Record_AUTOMATIC()
        Catch Ex As Exception
	  Response.Write("Error: " & Ex.Message)
	  Response.End()
        End Try
    End Sub
    Public Sub Save_New_Record_AUTOMATIC()
        ' SET TABLE NAME
        Dim strTableName As String = "TABLENAME"
        Dim myDA As New OleDb.OleDbDataAdapter("SELECT * FROM [" & strTableName & "];", "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE=" & Server.MapPath("/APP_DATA/myDATABASE.mdb") & ";")
        ' CREATE COMMAND BUILDER
        Dim cmd As New OleDb.OleDbCommandBuilder(myDA)
        Dim myDS As New DataSet
        ' FILL DATASET
        myDA.Fill(myDS, strTableName)
        ' NEW RECORD
        Dim myDR As DataRow = myDS.Tables(0).NewRow
        Try
	  ' SETS DATAROW VALUES FROM FDF - EXLUDING Autoincremental [ID] Field
	  myDR = cFDFDoc.FDFSetDataRowFromValues(myDR, "ID")
	  ' ADD NEW RECORD TO DATASET
	  myDS.Tables(strTableName).Rows.Add(myDR)
	  ' UPDATE DATASET
	  myDA.Update(myDS, strTableName)
        Catch ex As Exception
	  Throw ex
        End Try
        Return
    End Sub
    Public Sub Save_New_Record_MANUAL()
        ' SET TABLE NAME
        Dim strTableName As String = "TABLENAME"
        Dim myDA As New OleDb.OleDbDataAdapter("SELECT * FROM [" & strTableName & "];", "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE=" & Server.MapPath("/APP_DATA/myDATABASE.mdb") & ";")
        ' CREATE COMMAND BUILDER
        Dim cmd As New OleDb.OleDbCommandBuilder(myDA)
        Dim myDS As New DataSet
        ' FILL DATASET
        myDA.Fill(myDS, strTableName)
        ' NEW RECORD
        Dim myDR As DataRow = myDS.Tables(0).NewRow
        Try
	  ' SETS DATAROW VALUES FROM FDF - EXLUDING Autoincremental [ID] Field
	  myDR("FIELD_A") = cFDFDoc.FDFGetValue("FIELD_A", False)
	  myDR("FIELD_B") = cFDFDoc.FDFGetValue("FIELD_A", False) & " " & cFDFDoc.FDFGetValue("FIELD_C", False)
	  myDR("FIELD_D") = cFDFDoc.FDFGetValue("FIELD_D", False)
	  ' ADD NEW RECORD TO DATASET
	  myDS.Tables(strTableName).Rows.Add(myDR)
	  ' UPDATE DATASET

	  myDA.Update(myDS, strTableName)
        Catch ex As Exception
	  Throw ex
        End Try
        Return
    End Sub

End Class