Hi,
I have the following code:
I get a message stating Object Initialization can be simplified, which changes to this:
Why can't the Parameters form part of the "With" also?
Is there any documentation that details what properties each object can use in the "With" during Initialization?
Thank you.
I have the following code:
vb Code:
Dim cmd As New SqlCommand cmd.CommandText = SqlInsertVendor cmd.Parameters.Add("@job_number", SqlDbType.VarChar).Value = JobNo cmd.Parameters.Add("@vendor_name", SqlDbType.VarChar).Value = Me.txtVendorName.Text cmd.Parameters.Add("@vendor_code", SqlDbType.VarChar).Value = Me.txtVendorCode.Text
I get a message stating Object Initialization can be simplified, which changes to this:
vb Code:
Dim cmd As New SqlCommand With { .CommandText = SqlInsertVendor } cmd.Parameters.Add("@job_number", SqlDbType.VarChar).Value = JobNo cmd.Parameters.Add("@vendor_name", SqlDbType.VarChar).Value = Me.txtVendorName.Text cmd.Parameters.Add("@vendor_code", SqlDbType.VarChar).Value = Me.txtVendorCode.Text
Why can't the Parameters form part of the "With" also?
Is there any documentation that details what properties each object can use in the "With" during Initialization?
Thank you.