Link to home
Start Free TrialLog in
Avatar of MyExpqust15
MyExpqust15

asked on

Visual Basic

I have a couple of questions:
(1)      The first one question is how many occurrences can you have of  a Database connection string like so: Public con5 As New SqlConnection("Data Source = localhost\GECACSQL; Initial Catalog = Housingtwoyrsbck; Integrated Security= True")
    Public cmd5 As New Data.SqlClient.SqlCommand
(2)      
This is the syntax Error that keep repeating when I try to save 30 Day income calculation to database

Try
            cmd5.CommandType = System.Data.CommandType.Text




            cmd5.CommandText = " insert into 30dayIncome values ('" & txtclnt30dSsn.Text & "','" & txtclntFN.Text & "','" & txtclntLN.Text & "','" & dtpAppdt.Value.Date & "','" & txtdtpApp.Text & "','" & _
                                                                  dtpRng.Value.Date & "','" & txtRng.Text & "','" & txt30FnLncpy.Text & "','" & txtclnt1Income.Text & "','" & txtpaydt1.Text & "','" & txtgrsAmnt1.Text & "','" & _
                                                                  txtsrc2clnt.Text & "','" & txtpdclnt2.Text & "','" & txtgrss2clnt.Text & "','" & txtsrc3clnt.Text & "','" & txtpdt3clnt.Text & "','" & txtgrs3clnt.Text & "','" & _
                                                                  txtsrc4clnt.Text & "','" & txtpdt4clnt.Text & "','" & txtgrs4clnt.Text & "','" & txtErnTotclnt.Text & "','" & txtUnrnMonclt.Text & "','" & txtmem2.Text & "','" & _
                                                                  txtsrc1mem2.Text & "','" & txtpdt1m2.Text & "','" & txtgrsamnt2.Text & "','" & txtsrc2mem2.Text & "','" & txtpdt2m2.Text & "','" & txtgrs2m2.Text & "','" & _
                                                                  txtsrc3m2.Text & "','" & txtpdt3m2.Text & "','" & txtgrs3m2.Text & "','" & txtsrc4m2.Text & "','" & txtpdt4m2.Text & "','" & txtgrs4m2.Text & "','" & txterTm2.Text & "','" & _
                                                                  txtunrTm2.Text & "','" & txtmem3.Text & "','" & txtsrc1m3.Text & "','" & txtpdt1m3.Text & "','" & txtgrs1m3.Text & "','" & txtsrc2m3.Text & "','" & _
                                                                  txtpdt2m3.Text & "','" & txtgrs2m3.Text & "','" & txtsrc3m3.Text & "','" & txtpdt3m3.Text & "','" & txtgrs3m3.Text & "','" & txtsrc4m3.Text & "','" & txtpdt4m3.Text & "','" & _
                                                                  txtgrs4m3.Text & "','" & txternTm3.Text & "','" & txtUnrm3.Text & "','" & txtm4.Text & "','" & txtsrc1m4.Text & "','" & txtpdt1m4.Text & "','" & _
                                                                  txtgrs1m4.Text & "','" & txtsrc2m4.Text & "','" & txtpdt2m4.Text & "','" & txtgrs2m4.Text & "','" & txtsrc3m4.Text & "','" & txtpdt3m4.Text & "','" & txtgrs3m4.Text & "','" & _
                                                                  txtsrc4m4.Text & "','" & txtpdt4m4.Text & "','" & txtgrs4m4.Text & "','" & txternm4.Text & "','" & txtUnrm4.Text & "','" & cmbFpgLmt.SelectedItem & "','" & _
                                                                  cmbFPGYrLmt.SelectedItem & "','" & rdbysFPG.Checked & "','" & rdbnoFpg.Checked & "','" & cmbAMIyr.SelectedItem & "','" & txtfam30d.Text & "','" & rdbysAmi.Checked & "','" & _
                                                                  rdbnoAmi.Checked & "','" & txtgrndTot.Text & "','" & txtmnUnr.Text & "','" & txtnum30.Text & "','" & txtrepwk30.Text & "','" & txtgrssmonth.Text & "','" & _
                                                                  txtEstrnUnr.Text & "','" & txtEstAnn.Text & "','" & txtAnnUnrn.Text & "','" & txtAnnrnUnr.Text & "','" & cmbcnslr30d.SelectedItem & "','" & txtdtsgn.Text & "')"



            cmd5.Connection = con



            con5.Open()
            cmd5.ExecuteNonQuery()
            MsgBox("Succesfully addes", MsgBoxStyle.Information, "add")



        Catch ex As Exception

            MessageBox.Show(ex.Message)

            '  con5.Close()

        End Try
    End Sub

Open in new window

(3)      This button click is the first part of the calculation and the other 4 button are similar the calculation work fine it’s just isn’t being passed to the SQL Database like the other ones are?
Private Sub btnTot1_Click(sender As Object, e As EventArgs) Handles btnTot1.Click

        'This line of code calles Total 1 subroutine.
        'Tot1()

        unrnmon = FormatCurrency(txtUnrnMonclt.Text)

        ' Values are there then Gross Income textboxes are converted to decimal currency values.
        Clngrs1 = FormatCurrency(txtgrsAmnt1.Text)
        Clngrs2 = FormatCurrency(txtgrss2clnt.Text)
        Clngrs3 = FormatCurrency(txtgrs3clnt.Text)
        Clngrs4 = FormatCurrency(txtgrs4clnt.Text)

        'The individual gross incomes are added together for Grand Total * (4.33)for 30 day total
        ernincTot = Clngrs1 + Clngrs2 + Clngrs3 + Clngrs4

        txtErnTotclnt.Text = FormatCurrency(ernincTot * 4.33.ToString)
        hh1erntot = FormatCurrency(txtErnTotclnt.Text)

        grntot30 = FormatCurrency(txtgrndTot.Text)


        Dim strinput1, strinput2 As String
        Dim ysbol, nobol As Boolean

        nobol = False
        ysbol = True

        strinput1 = InputBox(" Does House Hould Member 2 have Income? Enter True or False ")

        If strinput1 = "" Then
            MsgBox(" You canceled ")

        ElseIf strinput1 = nobol Then
            MsgBox(" That's all the House Hold Income! ")



            txtgrndTot.Text = FormatCurrency(txtErnTotclnt.Text)
            txtmnUnr.Text = FormatCurrency(unrnmon.ToString)

        Else
            strinput2 = ysbol

            MsgBox(" You have a second person with income! Your Grand Total is increasing. ")

            grpMem2.Visible = True

            'End If
        End If


    End Sub

Open in new window

(4)
This code is at form load to be recognized throughout Form, I changed it because the Subroutine would not pass to Insert Code from VB to SQL?
Private Sub HousingAppMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

unrnmon = FormatCurrency(txtUnrnMonclt.Text)

                ernincTot = Clngrs1 + Clngrs2 + Clngrs3 + Clngrs4

        
        grntot30 = FormatCurrency(txtgrndTot.Text)

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MyExpqust15
MyExpqust15

ASKER

OK let me simplify, although I have to think specifically of what to ask, this means, It would be better if you tell me exactly how I should ask my question. So by the time I ask my question I may have already figured it out.
My point is simply this:

You've asked for help with 4 separate issues in your post here, and they're not really related related. Many Experts will see this and will simply not try to help you.

Instead, ask 4 separate questions. You'll find EE will work much better that way.

That said, I've responded to your issues, and what you should do now is review what I've suggested and try to implement that in your own project. If you don't understand something then post back here and ask for clarification, or more help. EE is very much a "two way street" - we don't know if you need more help unless you ask us for it!
I've requested that this question be deleted for the following reason:

question is to much for expert to answer, need simplified
I've provided suggestions to all of the Experts requests. I'll be glad to work with you to resolve any issues you have, but you have to provide me with feedback.
OK Scott, looking forward to working with you, I will be asking more questions next week.

Have a beautiful weekend!
you can use MSDN to resolve this problem