locked
Unable to Add a New Record to the database RRS feed

  • Question

  • User1958125286 posted

    Hi, 

    I am a beginer with VB.net and I am trying to figure out what I am doing wrong. Any help and suggestion will be appreciated. I do not the cut copy code but I do need some guidance. Thanks in advance. 

    Here is the situation:

    I developed an application and it had a sign up form which is still working and adding new records to the database. I am curretly trying to remove the sign up form and trying to add four diffrent sign up types for four different form types. 

    The entire code does not throw any expection nor any obj ref errors but it doesnt do the work as well. I mean the the data is not getting entered in the db. The db is accessible and the application is currently running. 

    I have tried to change the code a bit by adding connstrng in the vb and insert command directly but still its not doing a thing. 

    The signup.aspx.vb which is currently working is as follows

    Public Class signup
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            ApplicationUser.EnforceAuthentication()
        End Sub
    
      
        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
    
            Dim d As New nahelpDataSet
            Dim t As nahelpDataSet.avermentsDataTable = d.averments
            Dim r As nahelpDataSet.avermentsRow = t.NewavermentsRow
            Dim a As New nahelpDataSetTableAdapters.avermentsTableAdapter
    
            r.Cli_F_Name = txtCli_F_Name.Text
            r.Cli_M_Name = txtCli_M_Name.Text
            r.Cli_L_Name = txtCli_L_Name.Text
            r.Cli_Address = txtCli_Address.Text
            r.Cli_City = txtCli_City.Text
            r.Cli_State = txtCli_State.Text
            r.Cli_Zip = txtCli_Zip.Text
            r.Cli_Cell = txtCli_Cell.Text
            r.Cli_Email = txtCli_Email.Text
            r.Cli_SSN = txtCli_SSN1.Text & txtCli_SSN2.Text
            r.Cli_DOB = Date.Parse(String.Format("{0}/{1}/{2}", txtCli_DOB_Month.Text, txtCli_DOB_Day.Text, txtCli_DOB_Year.Text))
            r.Straw_Name = txtStraw_Name.Text
            r.Straw_State = txtStraw_State.Text
            r.Straw_County = txtStraw_County.Text
            r.Straw_County = txtStraw_City.Text
            r.Property_Address = txtProperty_Address.Text
            r.What_is_Reviewd = ddlwhat_is_reviewd.Text
            'r.Cli_SSN_Back = txtCli_SSN_Back.Text
            r.Cli_Drivers_License_No = txtCli_Drivers_License_No.Text
            'r.Cli_Birth_Certificate_No = txtCli_Birth_Certificate_No.Text
            'r.Cli_POB = txtCli_POB.Text
            'r.Cli_POB_City = txtCli_POB_City.Text
            'r.Cli_POB_State = txtCli_POB_State.Text
            'r.Cli_POB_Zip = txtCli_POB_Zip.Text
            r.SPC_State_Secretary = txtSPC_State_Secretary.Text
            'r.SPC_Client_City_Township = txtSPC_Client_City_Township.Text
            'r.NA_Recording_County_State = txtNA_Recording_County_State.Text
            r.Notary_State = txtNotary_State.Text
            r.Notary_County = txtNotary_County.Text
            r.Account_No = txtAccount_Number.Text
            r.First_Libelees_Name = txtFirst_Libelees_Name.Text
            r.First_Libelees_Address = txtFirst_Libelees_Address.Text
            r.First_Libelees_City = txtFirst_Libelees_City.Text
            r.First_Libelees_State = txtFirst_Libelees_State.Text
            r.First_Libelees_Zip = txtFirst_Libelees_Zip.Text
            r.Second_Libelees_Name = txtSecond_Libelees_Name.Text
            r.Recording_State = txtRecording_State.Text
            r.Recording_County = txtRecording_County.Text
            r.Who_Admin_Process = txtWho_Admin_Process.Text
            r.FF_Comments = txtFF_Comments.Text
            'r.Second_Libelees_Address = txtSecond_Libelees_Address.Text
            'r.Second_Libelees_City = txtSecond_Libelees_City.Text
            'r.Second_Libelees_State = txtSecond_Libelees_State.Text
            'r.Second_Libelees_Zip = txtSecond_Libelees_Zip.Text
            r.Notary_Presentor_Name = txtNotary_Presentor_Name.Text
            r.Notary_Presentor_POB = txtNotary_Presentor_POB.Text
            r.Notary_Presentor_City = txtNotary_Presentor_City.Text
            r.Notary_Presentor_State = txtNotary_Presentor_State.Text
            r.Notary_Presentor_Zip = txtNotary_Presentor_Zip.Text
    
            If ApplicationUser.UserLevel > 100 Then
    
    
                r.NA_Registered_Mail_No = txtNA_Registered_Mail_No.Text
                r.Total_Conversion = txtTotal_Conversion.Text
                r.Total_Conversion_Written_Out = txtTotal_Conversion_Written_Out.Text
                r.First_Mailing_Date = txtFirst_Mailing_Date.Text
                r.Second_Mailing_Date = txtSecond_Mailing_Date.Text
                r.Final_Mailing_Date = txtFinal_Mailing_Date.Text
                r.Mortgage_Amount_X4 = txtMortgage_Amount_X4.Text
                r.True_Bill_NIHIL_DICIT_Certified_Mail_No = txtTrue_Bill_NIHIL_DICIT_Certified_Mail_No.Text
                r.First_Notice_Certfied_Mail_No = txtFirst_Notice_Certfied_Mail_No.Text
                r.Original_Mortgage_Amount = txtOriginal_Mortgage_Amount.Text
    
                If txtSilver_Price.Text.Trim = "" Then
                    r.SetSilver_PriceNull()
                Else
                    r.Silver_Price = txtSilver_Price.Text
                End If
    
            End If
    
            r.Date_Created = Now
            r.Status = "New"
            r.Created_By = ApplicationUser.UserName
    
    
    
            t.AddavermentsRow(r)
            a.Update(d)
    
            With New nahelpDataSetTableAdapters.commentsTableAdapter
                .Insert(r.Id, Now, ApplicationUser.UserName, True, "Created")
            End With
    
            Session("ConfirmationNumber") = r.Id
    
            Response.Redirect("signup_confirm.aspx")
    
        End Sub
    End Class

     

    The adminprocess.aspx.vb which I newly developed is as follows

    Imports System.Data
    Imports System.Data.SqlClient
    
    Public Class AdminProcess
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            ApplicationUser.EnforceAuthentication()
        End Sub
    
    
        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
    
            Dim d As New nahelpDataSet
            Dim t As nahelpDataSet.avermentsDataTable = d.averments
            Dim r As nahelpDataSet.avermentsRow = t.NewavermentsRow
            Dim a As New nahelpDataSetTableAdapters.avermentsTableAdapter
    
            'Dim con As New SqlConnection
            'Dim cmd As New SqlCommand
            'Try
            'con.ConnectionString = "Data Source=spcclient.db.7254097.hostedresource.com; Initial Catalog=spcclient; User ID=spcclient; Password='Th3R0ck!'"
            'con.Open()
            'cmd.Connection = con
            'cmd.CommandText = "INSERT INTO averments (SPC_Paperwork_Type, Cli_F_Name, Cli_L_Name) VALUES (Admin Process, txtCli_F_Name.Text, txtCli_L_Name.Text)"
    
            'Catch ex As Exception
    
            'End Try
    
            r.SPC_Paperwork_Type = "Admin Process"
            r.Cli_F_Name = txtCli_F_Name.Text
            r.Cli_M_Name = txtCli_M_Name.Text
            r.Cli_L_Name = txtCli_L_Name.Text
            r.Cli_Address = txtCli_Address.Text
            r.Cli_City = txtCli_City.Text
            r.Cli_State = txtCli_State.Text
            r.Cli_Zip = txtCli_Zip.Text
            r.Cli_Cell = txtCli_Cell.Text
            r.Cli_Email = txtCli_Email.Text
            r.Cli_SSN = txtCli_SSN1.Text & txtCli_SSN2.Text
            r.Property_Address = txtProperty_Address.Text
            r.Notary_Presentor_Name = txtNotary_Presentor_Name.Text
            r.Notary_Presentor_POB = txtNotary_Presentor_POB.Text
            r.Notary_Presentor_City = txtNotary_Presentor_City.Text
            r.Notary_Presentor_State = txtNotary_Presentor_State.Text
            r.Notary_Presentor_Zip = txtNotary_Presentor_Zip.Text
            r.Account_No = txtAccount_no.Text
            r.First_Libelees_Name = txtFirst_Libelees_Name.Text
            r.First_Libelees_Address = txtFirst_Libelees_Address.Text
            r.First_Libelees_City = txtFirst_Libelees_City.Text
            r.First_Libelees_State = txtFirst_Libelees_State.Text
            r.Second_Libelees_Name = txtSecond_Libelees_Name.Text
            If ApplicationUser.UserLevel > 100 Then
    
    
                r.NA_Registered_Mail_No = txtNA_Registered_Mail_No.Text
                r.Total_Conversion = txtTotal_Conversion.Text
                r.Total_Conversion_Written_Out = txtTotal_Conversion_Written_Out.Text
                r.First_Mailing_Date = txtFirst_Mailing_Date.Text
                r.Second_Mailing_Date = txtSecond_Mailing_Date.Text
                r.Final_Mailing_Date = txtFinal_Mailing_Date.Text
                r.Mortgage_Amount_X4 = txtMortgage_Amount_X4.Text
                r.True_Bill_NIHIL_DICIT_Certified_Mail_No = txtTrue_Bill_NIHIL_DICIT_Certified_Mail_No.Text
                r.First_Notice_Certfied_Mail_No = txtFirst_Notice_Certfied_Mail_No.Text
                r.Original_Mortgage_Amount = txtOriginal_Mortgage_Amount.Text
    
                If txtSilver_Price.Text.Trim = "" Then
                    r.SetSilver_PriceNull()
                Else
                    r.Silver_Price = txtSilver_Price.Text
                End If
    
            End If
            r.Date_Created = Now
            r.Status = "New"
            r.Created_By = ApplicationUser.UserName
    
    
    
            t.AddavermentsRow(r)
            a.Update(d)
    
            With New nahelpDataSetTableAdapters.commentsTableAdapter
                .Insert(r.Id, Now, ApplicationUser.UserName, True, "Created")
            End With
    
            Session("ConfirmationNumber") = r.Id
    
            Response.Redirect("averments.aspx")
    
        End Sub
    End Class

     

    I will be waiting for an answer or suggestion. Thank you...

    Friday, February 18, 2011 12:04 PM

Answers

  • User1958125286 posted
    I have one question. Why the Signup.aspx.vb does the work and why the similar adminprocess.aspx.vb doesnt do the same work. Please ignore the single quotes in the adminprocess.aspx.vb . Thats where my concern is. I can share the project with you if you think my description isnt good enough.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 20, 2011 1:17 PM

All replies

  • User-691759321 posted

    You are using a lot of weird commands for a simple form submission.  Here is my suggestion based on your description of the application.

    1. Create a BasicForm class which has all members that are shared between forms.  These usually include name, city, state, etc. 

    2. Create a class for each of the types of forms which inherits from the BasicForm

    3. Give each of the type classes a method for insert, update, delete, and validation (if necessary)

    4. When the user clicks the submit button create a new instance of the class object passing it the fields on the page and then call the approriate method.

    From a standards point the data base connections should be in a separate data handler which simply accepts a sql string and connection string.  This way the data connection is not class specific and can be reused by anything.  The type classes will allow you store the form data is a simple object which can be reference very easily and update with a simple line of code.  I would drop all the ApplicationUser lines of code because they are not necessary.

    Friday, February 18, 2011 12:42 PM
  • User1958125286 posted
    I have one question. Why the Signup.aspx.vb does the work and why the similar adminprocess.aspx.vb doesnt do the same work. Please ignore the single quotes in the adminprocess.aspx.vb . Thats where my concern is. I can share the project with you if you think my description isnt good enough.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 20, 2011 1:17 PM
  • User-1412735316 posted

    If you feel comfortable then you may share your project with db at kmnur@hotmail.com. I will try my best you help you out.

    Sunday, February 20, 2011 1:30 PM