Avatar of Larry Brister
Larry Brister
Flag for United States of America asked on

Shorten vb code

My following code works fine...but takes up a lot of realestate.

Is there any way to shorten at leas the paramaters being fed in?

..shorten this part?
 oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter....


#Region "     Save Data     "
    'Save data to Server
    Private Sub rbSaveClientInformation_Click(sender As System.Object, e As System.EventArgs) Handles rbSaveClientInformation.Click
        Using objConn As SqlConnection = ngSqlConnectionString(CInt(My.Settings.isProduction))
            Using oCom As New SqlCommand
                oCom.Connection = objConn
                oCom.CommandText = "usp_BillMan_ClientEdit"
                oCom.CommandType = CommandType.StoredProcedure
                oCom.Parameters.Clear()
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ClientID", System.Data.SqlDbType.Int)).Value = Client_ID
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingAlias", System.Data.SqlDbType.VarChar, 200)).Value = IIf(Me.rtbBillingAlias.Text = "Add Billing Alias", DBNull.Value, Me.rtbBillingAlias.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@association", System.Data.SqlDbType.VarChar, 200)).Value = Me.ddlClientAssociation.Text
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingAddress", System.Data.SqlDbType.VarChar, 300)).Value = IIf(Me.txtBillStreet.Text = "Contact Client Maintenance", DBNull.Value, Me.txtBillStreet.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingCity", System.Data.SqlDbType.VarChar, 50)).Value = IIf(Me.txtBillCity.Text = "Contact Client Maintenance", DBNull.Value, Me.txtBillCity.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingState", System.Data.SqlDbType.VarChar, 2)).Value = Me.ddlBillState.SelectedValue
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingZip", System.Data.SqlDbType.VarChar, 10)).Value = IIf(Me.txtBillZip.Text = "Contact Client Maintenance", DBNull.Value, Me.txtBillZip.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LocationAddress", System.Data.SqlDbType.VarChar, 300)).Value = IIf(Me.txtLocStreet.Text = "Contact Client Maintenance", DBNull.Value, Me.txtLocStreet.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LocationCity", System.Data.SqlDbType.VarChar, 50)).Value = IIf(Me.txtLocCity.Text = "Contact Client Maintenance", DBNull.Value, Me.txtLocCity.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LocationState", System.Data.SqlDbType.VarChar, 2)).Value = Me.ddlLocState.SelectedValue
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LocationZip", System.Data.SqlDbType.VarChar, 10)).Value = IIf(Me.txtLocZip.Text = "Contact Client Maintenance", DBNull.Value, Me.txtLocZip.Text)
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingTemplate", System.Data.SqlDbType.VarChar, 300)).Value = Me.ddlBillingTemplate.SelectedValue
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PaymentTerms", System.Data.SqlDbType.VarChar, 20)).Value = Me.ddlPaymentTerms.SelectedValue
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@InvoiceSendMethod", System.Data.SqlDbType.VarChar, 20)).Value = Me.ddlInvoiceSendMethod.SelectedValue
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@BillingNotes", System.Data.SqlDbType.VarChar, 4000)).Value = Me.rtbBillingNotes.Text
                oCom.Parameters.Add(New System.Data.SqlClient.SqlParameter("@modifiedBy", System.Data.SqlDbType.VarChar, 30)).Value = Environment.UserName

                objConn.Open()

                Dim dr = oCom.ExecuteReader()
                dr.Read()

                If dr.HasRows Then
                    If MsgBox("Data Updated - Close CLient?", vbYesNo, "Choose Yes to close Client Edit Form") = MsgBoxResult.Yes Then
                        'Refresh data and close form
                        Main.LoadCLientAsDefault()
                        Main.Show()
                        Me.Close()
                    Else
                        'Just refresh data
                        loadInforData(dr("ClientName"), (dr("ClientID")))
                    End If
                End If
            End Using
        End Using
        System.GC.Collect()
        Me.rbSaveClientInformation.Enabled = True
    End Sub
#End Region

Open in new window

Visual Basic.NET.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
Larry Brister

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Paul Jackson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Larry Brister

ASKER
Thanks
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes