VB.NET retrieving Values from a db

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi There,
I have this question, below is the piece of code that I have written on a Button Click event and what it does is it takes all the values from the text boxes and Combo boxes and inserts them into the Datagridview control, this code works great but would like to pull one of the values from a table which is "0501", "0551", "0601" and also highlighted in the code. please let me know how this can be accomplished.
Private Sub BtnAddRows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAddRows.Click
DtGridView.ColumnCount = 7
DtGridView.ColumnHeadersVisible = True
Set the column header style.
Dim columnHeaderStyle As New DataGridViewCellStyle()
columnHeaderStyle.BackColor = Color.Beige
columnHeaderStyle.Font = New Font("Verdana", 7, FontStyle.Bold)
columnHeaderStyle.WrapMode = DataGridViewTriState.True
DtGridView.ColumnHeadersDefaultCellStyle = columnHeaderStyle

Set the column header names.
DtGridView.Columns(0).Name = "Item Number"
DtGridView.Columns(1).Name = "Vendor"
DtGridView.Columns(2).Name = "Size"
DtGridView.Columns(3).Name = "Item Description"
DtGridView.Columns(4).Name = "Unit Of Measure"
DtGridView.Columns(5).Name = "Item Class"
DtGridView.Columns(6).Name = "Current Cost"
If CboSize.Text = "SHOES" Then
DtGridView.ClearSelection()
Dim rowNum As Integer = DtGridView.Rows.Add()
Dim Str As String
Dim VendID As String
Str = cboVendor.Text
VendID = Str.Substring(0, 5)

DtGridView.Rows.Item(rowNum).Cells(0).Value = String.Join("-", New String() {CType(cboVendor.SelectedValue, DataRowView)("VENDORSKUCODE").ToString, Me.txtStyle.Text, CType(cboPrimaryColor.SelectedValue, DataRowView)("ColorNumber").ToString & CType(cboSecondaryColor.SelectedValue, DataRowView)("ColorNumber").ToString}) + "-" + "0551"
DtGridView.Rows.Item(rowNum).Cells(1).Value = VendID
DtGridView.Rows.Item(rowNum).Cells(2).Value = CboSize.Text
DtGridView.Rows.Item(rowNum).Cells(3).Value = TxtItmDesc.Text
DtGridView.Rows.Item(rowNum).Cells(4).Value = CboUOM.Text
DtGridView.Rows.Item(rowNum).Cells(5).Value = CboItmClass.Text
DtGridView.Rows.Item(rowNum).Cells(6).Value = TxtCurrCost.Text
Dim rownum1 As Integer = DtGridView.Rows.Add()
DtGridView.Rows.Item(rownum1).Cells(0).Value = String.Join("-", New String() {CType(cboVendor.SelectedValue, DataRowView)("VENDORSKUCODE").ToString, Me.txtStyle.Text, CType(cboPrimaryColor.SelectedValue, DataRowView)("ColorNumber").ToString & CType(cboSecondaryColor.SelectedValue, DataRowView)("ColorNumber").ToString}) + "-" + "0601"
DtGridView.Rows.Item(rownum1).Cells(1).Value = VendID
DtGridView.Rows.Item(rownum1).Cells(2).Value = CboSize.Text
DtGridView.Rows.Item(rownum1).Cells(3).Value = TxtItmDesc.Text
DtGridView.Rows.Item(rownum1).Cells(4).Value = CboUOM.Text
DtGridView.Rows.Item(rownum1).Cells(5).Value = CboItmClass.Text
DtGridView.Rows.Item(rownum1).Cells(6).Value = TxtCurrCost.Text
Dim rownum2 As Integer = DtGridView.Rows.Add()
DtGridView.Rows.Item(rownum2).Cells(0).Value = String.Join("-", New String() {CType(cboVendor.SelectedValue, DataRowView)("VENDORSKUCODE").ToString, Me.txtStyle.Text, CType(cboPrimaryColor.SelectedValue, DataRowView)("ColorNumber").ToString & CType(cboSecondaryColor.SelectedValue, DataRowView)("ColorNumber").ToString}) + "-" + "0651"
DtGridView.Rows.Item(rownum2).Cells(1).Value = VendID
DtGridView.Rows.Item(rownum2).Cells(2).Value = CboSize.Text
DtGridView.Rows.Item(rownum2).Cells(3).Value = TxtItmDesc.Text
DtGridView.Rows.Item(rownum2).Cells(4).Value = CboUOM.Text
DtGridView.Rows.Item(rownum2).Cells(5).Value = CboItmClass.Text
DtGridView.Rows.Item(rownum2).Cells(6).Value = TxtCurrCost.Text
DtGridView.AllowUserToAddRows = False
BtnAddRows.Enabled = False
Else
DtGridView.Refresh()
MsgBox("yet To Code")
End If
End Sub
Farquest

View the full article
 
Back
Top