troubleshooting Question

Shorten vb code

Avatar of Larry Brister
Larry BristerFlag for United States of America asked on
.NET ProgrammingVisual Basic.NETMicrosoft Development
2 Comments1 Solution422 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Paul Jackson
Software Engineer
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros