Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlDataReader
Imports System.Data.SqlClient.SqlConnection

Public Class Order
    Inherits System.Windows.Forms.Form

    Dim myConnection As New SqlConnection
    Dim myCommand As New SqlCommand
    Dim ds As New DataSet
    Dim cmdtext As Integer
    Dim action As String
    Dim view As DataView
    Dim dr As SqlDataReader

    Sub fill()

        Dim adp As New SqlDataAdapter
        ds = New DataSet
        adp.SelectCommand = New SqlCommand
        adp.SelectCommand.Connection = myConnection
        adp.SelectCommand.CommandText = "select * from customer"
        Try
            adp.Fill(ds, "customer")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        view = New DataView(ds.Tables("customer"))

    End Sub

    Private Sub FillCombo()

        Dim adp As New SqlDataAdapter
        ds = New DataSet
        adp.SelectCommand = New SqlCommand
        adp.SelectCommand.Connection = myConnection
        adp.SelectCommand.CommandText = "select c_id FROM customer ORDER BY c_id"
        Try
            adp.Fill(ds)
            ComboBox1.ValueMember = "c_id"
            ComboBox1.DataSource = ds.Tables(0)
            ComboBox1.SelectedIndex = 0
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        view = New DataView(ds.Tables("customer"))
    End Sub

    Private Sub Binding()


        txtb2.DataBindings.Clear()
        txtb3.DataBindings.Clear()
        txtb4.DataBindings.Clear()
        txtb2.DataBindings.Add("text", view, "c_name")
        txtb3.DataBindings.Add("text", view, "c_add")
        txtb4.DataBindings.Add("text", view, "c_phno1")

    End Sub

Private Sub Order_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myConnection = New SqlConnection("Data Source=RUSHIKES-1A6789\SQLEXPRESS;Initial Catalog=AutoParts;Integrated Security=True")

        FillCombo()
        Binding()
        ComboBox1.DataSource = view

    End Sub

----------------------------------------------------------------------------------------

Error throwing at lines :

txtb2.DataBindings.Add("text", view, "c_name")
        txtb3.DataBindings.Add("text", view, "c_add")
        txtb4.DataBindings.Add("text", view, "c_phno1")

----------------------------------------------------------------------------------------

Thanx in Advance !

Edited 6 Years Ago by rick.eavans: n/a

Change: select c_id FROM customer ORDER BY c_id

Private Sub FillCombo()

        Dim adp As New SqlDataAdapter
        ds = New DataSet
        adp.SelectCommand = New SqlCommand
        adp.SelectCommand.Connection = myConnection
        adp.SelectCommand.CommandText = "select * FROM customer ORDER BY c_id"
        Try
            adp.Fill(ds)
            ComboBox1.ValueMember = "c_id"
            ComboBox1.DataSource = ds.Tables(0)
            ComboBox1.SelectedIndex = 0
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        view = New DataView(ds.Tables("customer"))
    End Sub
This article has been dead for over six months. Start a new discussion instead.