dcsimg
Results 1 to 8 of 8

Thread: Binding a textbox to a code built datagrid

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Binding a textbox to a code built datagrid

    Hi,

    I am trying to bind a textbox databindings (text) to the select field of my datagridview i have done this in code rather than the GUI because of my SQL select statment.

    As my PracticeDB is quite old records from 05/12/2014 i have had to use a sepecified date. But i plan to use the current date and return that in my query.

    Here is my code:

    Code:
        Private Sub Form11_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=JAMESPC\SUPPORTDB;Initial Catalog=Support_DB;Persist Security Info=True;User ID=username;Password=password")
            Dim QueryOpen As String = "Select * from ['Job info$'] where [Due on site] > Convert(datetime, '05/12/2014') AND [Job Completed?]= 0 order by [Job Number] desc"
            Dim DataAdpt As New SqlDataAdapter(QueryOpen, Sqlcon)
            Dim ds As New DataSet()
            Sqlcon.Open()
            DataAdpt.Fill(ds, "['Job_Info$']")
            Sqlcon.Close()
            DataGridView1.DataSource = ds
            DataGridView1.DataMember = "['Job_Info$']"
            txtcust.DataBindings.Add("Test", ds, "Customer")
            'txtequip.DataBindings.Add("Text", ds, "[Type of Equipment]")
        End Sub
    The datagrid populates correctly, but on running
    Code:
    txtcust.DataBindings.Add("Test", ds, "Customer")
    It errors woth Cannot bind to the property or column Customer on the DataSource.

    I maybe doing this wrong but my plan is once i have some more updated records in it my SQL query will be something like

    Code:
     
    Dim QueryOpen As String = "Select * from ['Job info$'] where [Due on site] > Current Date AND [Job Completed?]= 0 order by [Job Number] desc"
    Thanks James
    Last edited by VBJames; Jun 13th, 2019 at 10:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width