none
How to Run time Bind Dataset to datagrid using Binding in VB.NET 2005 ? RRS feed

  • Question

  • Hi
    Output i required is :

    1.I just want 2 fetch the data(all) in the table in run time according to user input & display in Datagridview.

    2.The database table i have created is run time.i need to create a run time dataset to fetch all data from the created run time table.(what,how & where to use typed dataset & untyped dataset & how to bind 2 datagrid to display) ?

    3..Also i want to fetch date wise(how to write a condition to fetch rows - the user input date(from date) ?

    This is my code:
    -----------------------

    Imports System.Data.SqlClient
    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim con As New SqlConnection
            con = New SqlConnection("Data Source=SYSTEM;Initial Catalog=trail;Integrated Security=True;Pooling=False")
            con.Open()

            Dim myds As DataSet = New DataSet("mydataset")
            Dim myadapter As SqlDataAdapter = New SqlDataAdapter("select * from table1", con)
            myadapter.Fill(myds, "table1")

            myadapter.TableMappings.Add("Table1", "textbox1")
            myadapter.Fill(myds)
            DataGrid1.DataSource = myds.DefaultViewManager

            DataGrid1.DataBindings.Add(New Binding("combo1", myds, "table1"))
           
        End Sub
    -----------------------------------------------Error Generated for the above code-----------------------------
    when i run this code It generates an error:

     "Cannot bind to the property 'combo1' on the target control.'Parameter name: PropertyName "

    ----------------------------------------------------------------------------------------------------------------------------
    I changed combo1 to text then textbox But None works. Also pls explain why this error generates where it went wrong ?

    reply asap
    dotnetnewbie
    Thursday, March 27, 2008 5:34 AM

All replies

  • Hi,

    To fetch the data according to user input, you have to include where condition in the select query.
    for eg:    Dim myadapter As SqlDataAdapter = New SqlDataAdapter("select * from table1 where ColumnName="+textbox1.text, con)

    to fill the datagrid with data,just use the line
     datagrid1.datasource=myDS

    i'm not clear about the third point. can you explain me?

    Are you using any combo box in the grid? what are you trying to do by this line?
    DataGrid1.DataBindings.Add(New Binding("combo1", myds, "table1")) 


    Monday, May 5, 2008 12:26 PM
  • Hi Jackuline
    The data are fetched from the database &(say customer name) list it in the combo box or list box (not text box) then as soon as the user selects any customer name listed in the combo box or list box (again it has to fetch from the database of that customer details such as address etc., How they are generated using dataset & datagrid.

    Pls ask me if you get any more doubts & or mail i can send the screen shot dotnetguy2k8@gmail.com

    dotnetguy
    Wednesday, June 18, 2008 5:14 PM