Solved

DataBinding Issue

Posted on 2015-02-18
3
74 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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