Solved

DataBinding Issue

Posted on 2015-02-18
3
72 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
Comment Utility
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
Comment Utility
This fixed my problem.

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 21
Check if number is currency 15 28
Check my code out(2) 1 26
bulid json format 3 16
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now