Solved

DataBinding Issue

Posted on 2015-02-18
3
75 Views
Last Modified: 2015-02-19
I am having a problem Binding text boxes

In the example below I would like to bind text boxes (and perhaps other controls) with the the column row I get from the query.

Currectly I am getting error:

{"Cannot bind to the property or column strCustomerType on the DataSource. Parameter name: dataMember"}

Imports System.Data
Imports System.Data.SqlClient

Public Class frmOEOrder
    Dim SQL As New SQLControl
    Public SQLCmd As SqlCommand

    Public Sub New(ByVal ID As String)
        ' This call is required by the designer.
        InitializeComponent()
        Dim PopulateCustomerQuery As String = "SELECT * FROM tblARCustomer WHERE strCustomerID ='" & ID & "'"
        If SQL.HasConnection = True Then
            SQL.RunQuery(PopulateCustomerQuery)

            'check dataset for tables before attempting to FILL DataGridView
            If SQL.SQLDataSet.Tables.Count > 0 Then
                'Populate DataGridView with DataSet
                dgvData.DataSource = SQL.SQLDataSet.Tables(0)
                BS.DataSource = SQL.SQLDataSet

                cboCustomerID.Text = SQL.SQLDataSet.Tables(0).Rows(0).Item(0).ToString
            End If
        End If
        PopulateData(SQL.SQLDataSet)
    End Sub

    Private Sub cmdQuery_Click(sender As Object, e As EventArgs) Handles cmdQuery.Click
        If txtQuery.Text <> "" Then
            If SQL.HasConnection = True Then
                SQL.RunQuery(txtQuery.Text)

                'check dataset for tables before attempting to FILL DataGridView
                If SQL.SQLDataSet.Tables.Count > 0 Then
                    'Populate DataGridView with DataSet
                    dgvData.DataSource = SQL.SQLDataSet.Tables(0)
                End If
            End If
        End If
    End Sub

    Private Sub PopulateData(ds As DataSet)
        'Procedure to bind data to controls
        BS.DataSource = ds
        strCustomerType.DataBindings.Add("Text", BS, "strCustomerType", True)
    End Sub

Open in new window

0
Comment
Question by:smartoffices
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 40618420
Since you're binding to a DataSet you will probably need to specify the table name in the binding expression.
Something like:
strCustomerType.DataBindings.Add("Text", BS, "[YourTable].strCustomerType", True)

Open in new window

0
 

Author Comment

by:smartoffices
ID: 40618683
This fixed my problem.

strCustomerType.DataBindings.Add("Text", SQL.SQLDataSet.Tables(0), "strCustomerType")
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question