none
Visual Studio, .net, form, datagridview RRS feed

  • Question

  • I'm working with a datagridview and I'm getting build errors. I had tables that were tied to the datagridview from a SQL back-end and everything was working fine.

    However I since completely deleted one of the tables and re-created it (using the same name (table name) and different column names). I also added a new data source. Ever since I did this my application has been a mess. 

    I've added a couple of new forms for end-users wishes. I have all the simple things such as navigation working at the moment and the other forms with datagridview's appear to be tied to the SQL back-end tables just fine. It's only this one table that I is NOT loading the SQL tables in the datagridview.

    Public Class Form2
    
    
        'DataTable
        Private sendList As New DataTable()
        Private dsSuppliers As New DataTable()
    
        'Datebase Connections
        Private dbCon As New DatabaseConnections
    
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Open connection
            dbCon.openConnection(My.Settings.SupplyChainConnStr)
    
            'Update searching data
            UpdateDataSet()
    
            'Set dataset of datagridview to our searching table
            tbl_Suppliers.DataSource = dsSuppliers
    
            'Refresh data to insure it loaded properly
            tbl_Suppliers.Refresh()
        End Sub
    
        'Update datasets
        Private Sub UpdateDataSet()
            'Fill Table adapter
            Me.CombinedDataTableAdapter.Fill(Me.SupplyChainDataSet.CombinedData)
    
            'Update our searching table
            dsSuppliers = Me.SupplyChainDataSet.CombinedData
        End Sub
    
        Private Sub Tbl_SSP_SuppliersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Tbl_SSP_SuppliersBindingNavigatorSaveItem.Click
            Me.Validate()
            Me.Tbl_SSP_SuppliersBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.SupplyChainDataSet)
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnContactfrm.Click
            My.Forms.ContactForm.Text = Now.ToString
            My.Forms.ContactForm.Show()
        End Sub
    
        Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
            Me.Close()
        End Sub
    
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
            searchSuppliers()
        End Sub
    
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles btnClear.Click
            txtParentSupplierCode.Text = ""
            txtPortalID.Text = ""
            txtConcatID.Text = ""
            txtUniqueID.Text = ""
            txtSupplierID.Text = ""
            txtSupplierName.Text = ""
            txtLastName.Text = ""
            txtCity.Text = ""
            txtSBU.Text = ""
            txtAddress.Text = ""
            lblSearchResults.Text = dsSuppliers.Rows.Count & " / " & dsSuppliers.Rows.Count & "Records Found"
            searchSuppliers()
        End Sub
    
        Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
            Dim res As Results
            Dim temp As New DataTable()
            Dim dRow As DataRow = Nothing
            Dim uID As Object = Nothing
            Dim pID As Object = -1
    
            If txtPortalID.ReadOnly Then
                MsgBox("Update mode has been enabled, please clear selection to add a new supplier.", MsgBoxStyle.Information, "Note")
                Exit Sub
            End If
    
            txtPortalID.Text = ""
    
            If 0 <> searchSuppliers() Then
                If DialogResult.Cancel = MsgBox("This supplier has been found to not be unique, do you still wish to continue adding this supplier?", MsgBoxStyle.OkCancel, "New Supplier Warning!") Then
                    Exit Sub
                End If
            End If
    
            If DialogResult.OK = MsgBox("Please confirm that you would like to add this supplier.", MsgBoxStyle.OkCancel, "Add Verfication.") Then
                uID = txtUniqueID.Text
    
                temp = dsSuppliers.Clone()
                dRow = temp.NewRow()
    
                With dRow
                    .Item("parentsuppliercode") = txtParentSupplierCode.Text
                    .Item("portalID") = txtPortalID.Text
                    .Item("concatID") = txtConcatID.Text
                    .Item("uniqueID") = IIf("" = uID, DBNull.Value, uID)
                    .Item("supplierID") = txtSupplierID.Text
                    .Item("supplierName") = txtSupplierName.Text
                    .Item("lastname") = txtLastName.Text
                    .Item("city") = txtCity.Text
                    .Item("sbu") = txtSBU.Text
                    .Item("address") = txtAddress.Text
    
                End With
    
                temp.Rows.Add(dRow)
    
                res = dbCon.insertData("tbl_SSP_Suppliers", temp)
    
                If res.isReady Then
                    MsgBox("Supplier Added!", MsgBoxStyle.Exclamation, "Success")
    
                    temp = res.data
    
                    With temp.Rows(0)
                        pID = .Item("portalID")
                    End With
    
                    'Update searching data
                    UpdateDataSet()
    
                    tbl_Suppliers.DataSource = dsSuppliers
                    lblSearchResults.Text = dsSuppliers.Rows.Count & " / " & dsSuppliers.Rows.Count & " Records Found"
                    txtPortalID.ReadOnly = True
                    txtPortalID.Text = pID
                    searchSuppliers()
                Else
                    MsgBox("Failed to add supplier!", MsgBoxStyle.Critical, "Error")
                End If
            End If
        End Sub
    
        Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
            Dim res As Results
    
            If txtPortalID.ReadOnly Then
                If DialogResult.OK = MsgBox("Please confirm the supplier selected is the supplier you wish to delete.", MsgBoxStyle.OkCancel, "Delete Confirm") Then
                    res = dbCon.deleteData("DELETE FROM tbl_SSP_Suppliers WHERE portalID = " & txtPortalID.Text)
    
                    If res.isReady Then
                        MsgBox("Supplier Deleted!", MsgBoxStyle.Exclamation, "Success")
                        btnClear.PerformClick()
    
                        'Update searching data
                        UpdateDataSet()
    
                        tbl_Suppliers.DataSource = dsSuppliers
                        lblSearchResults.Text = dsSuppliers.Rows.Count & " / " & dsSuppliers.Rows.Count & " Records Found"
                    Else
                        MsgBox("Failed to delete supplier!", MsgBoxStyle.Critical, "Error")
                    End If
                End If
            Else
                MsgBox("Please select a supplier before trying to delete!", MsgBoxStyle.Information, "No Supplier Selected")
            End If
        End Sub
    
        Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
            Dim res As Results
            Dim temp As New DataTable()
            Dim dRow As DataRow = Nothing
            Dim uID As Object = Nothing
    
            If txtPortalID.ReadOnly Then
                If DialogResult.OK = MsgBox("Please confirm that you would like to update this supplier.", MsgBoxStyle.OkCancel, "Update Verfication.") Then
                    uID = txtUniqueID.Text
    
                    temp = dsSuppliers.Clone()
                    dRow = temp.NewRow()
    
                    With dRow
                        .Item("parentsuppliercode") = txtParentSupplierCode.Text
                        .Item("portalID") = txtPortalID.Text
                        .Item("concatID") = txtConcatID.Text
                        .Item("uniqueID") = IIf("" = uID, DBNull.Value, uID)
                        .Item("supplierID") = txtSupplierID.Text
                        .Item("supplierName") = txtSupplierName.Text
                        .Item("lastname") = txtLastName.Text
                        .Item("city") = txtCity.Text
                        .Item("sbu") = txtSBU.Text
                        .Item("address") = txtAddress.Text
    
                    End With
    
                    temp.Rows.Add(dRow)
    
                    res = dbCon.updateData("tbl_SSP_Suppliers", temp)
    
                    If res.isReady Then
                        MsgBox("Supplier Updated!", MsgBoxStyle.Exclamation, "Success")
    
                        'Update searching data
                        UpdateDataSet()
    
                        tbl_Suppliers.DataSource = dsSuppliers
                        lblSearchResults.Text = dsSuppliers.Rows.Count & " / " & dsSuppliers.Rows.Count & " Records Found"
                        searchSuppliers()
                    Else
                        MsgBox("Failed to update supplier!", MsgBoxStyle.Critical, "Error")
                    End If
                End If
            Else
                MsgBox("Please select a supplier before trying to update!", MsgBoxStyle.Information, "No Supplier Selected")
            End If
        End Sub
    
        Private Function searchSuppliers() As Integer
            Dim temp As New DataTable()
            Dim fType As String = " " & cmbFilterType.SelectedItem & " "
            Dim fObj As Object() = {
                New With {.column = "parentsuppliercode", .operator = "N", .value = txtParentSupplierCode.Text},
                New With {.column = "portalID", .operator = "=N", .value = txtPortalID.Text},
                New With {.column = "concatID", .operator = "=", .value = txtConcatID.Text},
                New With {.column = "uniqueID", .operator = "=N", .value = txtUniqueID.Text},
                New With {.column = "supplierID", .operator = "=", .value = txtSupplierID.Text},
                New With {.column = "supplierName", .operator = "%", .value = txtSupplierName.Text},
                New With {.column = "lastname", .operator = "=", .value = txtLastName.Text},
                New With {.column = "[city]", .operator = "%", .value = txtCity.Text},
                New With {.column = "sbu", .operator = "=", .value = txtSBU.Text},
                New With {.column = "[address]", .operator = "%", .value = txtAddress.Text}
            }
            Dim fStr As String = ""
            Dim dtRows As DataRow() = Nothing
    
            For Each fVal As Object In fObj
                If "" <> fVal.value Then
                    If "" <> fStr Then fStr += fType
                    Select Case fVal.operator
                        Case "="
                            fStr += "(" & fVal.column & " = '" & fVal.value & "')"
                        Case "=N"
                            fStr += "(" & fVal.column & " = " & fVal.value & ")"
                        Case "%"
                            fStr += "(" & fVal.column & " LIKE '%" & fVal.value & "%')"
                    End Select
                End If
            Next
    
            dtRows = dsSuppliers.Select(fStr)
    
            temp = dsSuppliers.Clone()
    
            For Each dRow As DataRow In dtRows
                temp.ImportRow(dRow)
            Next
    
            lblSearchResults.Text = temp.Rows.Count & " / " & dsSuppliers.Rows.Count & " Records Found"
            tbl_Suppliers.DataSource = temp
    
            Return temp.Rows.Count
        End Function
    
        Private Sub tbl_Suppliers_DoubleClick(sender As Object, e As EventArgs)
            If 1 = tbl_Suppliers.SelectedRows.Count Then
                With tbl_Suppliers.SelectedRows(0)
                    txtParentSupplierCode.Text = .Cells("parentsuppliercode").Value().ToString()
                    txtPortalID.ReadOnly = True
                    txtPortalID.Text = .Cells("portalID").Value()
                    txtConcatID.Text = .Cells("concatID").Value().ToString()
                    txtUniqueID.Text = .Cells("uniqueID").Value().ToString()
                    txtSupplierID.Text = .Cells("supplierID").Value().ToString()
                    txtSupplierName.Text = .Cells("supplierName").Value().ToString()
                    txtLastName.Text = .Cells("lastname").Value().ToString()
                    txtCity.Text = .Cells("city").Value().ToString()
                    txtSBU.Text = .Cells("sbu").Value().ToString()
                    txtAddress.Text = .Cells("address").Value().ToString()
                    searchSuppliers()
                End With
            End If
        End Sub
    
        Private Sub txtPortalID_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPortalID.KeyPress
            Dim keyCode As Integer = Asc(e.KeyChar)
    
            If 8 <> keyCode Then
                If 13 = keyCode Then
                    searchSuppliers()
                    e.Handled = True
                ElseIf keyCode < 48 Or keyCode > 57 Then
                    e.Handled = True
                End If
            End If
        End Sub
    
        Private Sub txtUniqueID_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUniqueID.KeyPress
            Dim keyCode As Integer = Asc(e.KeyChar)
    
            If 8 <> keyCode Then
                If 13 = keyCode Then
                    searchSuppliers()
                    e.Handled = True
                ElseIf keyCode < 48 Or keyCode > 57 Then
                    e.Handled = True
                End If
            End If
        End Sub
    
        Private Sub btnParentSupplierCode_Click(sender As Object, e As EventArgs) Handles btnParentSupplierCode.Click
            My.Forms.ParentSupplierForm.Text = Now.ToString
            My.Forms.ParentSupplierForm.Show()
        End Sub
    End Class

    Friday, November 17, 2017 2:59 PM

All replies

  • Have you tried from the data source window


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, November 17, 2017 3:14 PM
    Moderator
  • I have not Karen. I think there's something wrong with the syntax specifically anywhere that "tbl_Suppliers" is referenced. There's 8 build errors on the first screenshot. I know it's hard to see. 

    Friday, November 17, 2017 3:26 PM
  • I had no troubles seeing the errors. They are indicating tbl_Suppliers does not exists. This is why I recommended to re-configure the data source.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, November 17, 2017 3:37 PM
    Moderator
  • I did try that and tried it with multiple different data sources non of them will load because the same error is thrown everytime.

    Friday, November 17, 2017 4:22 PM
  • I found the answer to be that the datagridview's name needed to be set to tbl_Suppliers. That resolved my issue. 
    Monday, November 20, 2017 4:18 PM
  • I found the answer to be that the datagridview's name needed to be set to tbl_Suppliers. That resolved my issue. 

    tbl_Supplier is not a good name for a DataGridView and threw me off as tbl_ to me represents a table (e.g. DataTable or a concrete class representing data from a database)

    Suggestive name dgvSuppliers where dgv is a common prefix for a DataGridView. I on the other hand would use SuppliersDataGridView.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 20, 2017 4:52 PM
    Moderator
  • Hi stillanoob,

    Glad to hear this issue has been solved by yourself. Thanks for your sharing, I will introduce this experience to other forum users who face the same condition.
    Please mark your reply to close this case.


    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 28, 2017 6:43 AM
    Moderator