none
VB Forms and SQL Data

    Question

  • I created a database table it has three fields. TextID(PK), NAME, Text. I want to use this to fill say headers and text segments on a form. For instance one text says my company, LLC Intranet. I create a data source even created the query to only pull that particular record. For some reason when I  place a text box, label anything on the form and run my app the text that is in the SQL field does not appear on the form. Yes I am a rookie but I could use some help understanding why I cannot just place the data source in the form and have the selected data appear. THanks for any help in advance
    Monday, April 13, 2009 5:35 AM

Answers

  • The first thing that come to mind is the binding. Did you bind the TextBox to the datasource?

    Just putting a data source on a form won't automatically bind the controls on the form. Unless you used the datasource to create the controls on the form.

    For example, if you create a datasource and then drag it from the DataSources window to the form, it will create the controls for you and automatically bind them. But any other controls you add won't be bound.

    This is necessary because you can have any number of binding sources on a form. So there is no automatic assumption that the controls bind to any particular binding source.

    Hope this helps.

    • Proposed as answer by DeborahKMVP Tuesday, April 14, 2009 3:51 PM
    • Marked as answer by Kira Qian Friday, April 17, 2009 5:57 AM
    Monday, April 13, 2009 4:48 PM
  • Hi ASK Florida,

    To retrieve data from database, you can use SqlDataAdapter and fill the result to a DataTable or DataSet.

    SqlDataAdapter Class
    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

    Connecting and Retrieving Data in ADO.NET
    http://msdn.microsoft.com/en-us/library/ms254937(VS.80).aspx

    After ensure that you have get all the data you want from database correctly. you can bind them to some data controls such as TextBox, ComboBox, DataGridView. Or just assign the value to the TextBox control, do not use databinding.

    DataBinding
    http://www.codeproject.com/KB/database/databindingconcepts.aspx

    Sincerely,
    Kira Qian


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Kira Qian Friday, April 17, 2009 5:57 AM
    Wednesday, April 15, 2009 5:48 AM

All replies

  • The first thing that come to mind is the binding. Did you bind the TextBox to the datasource?

    Just putting a data source on a form won't automatically bind the controls on the form. Unless you used the datasource to create the controls on the form.

    For example, if you create a datasource and then drag it from the DataSources window to the form, it will create the controls for you and automatically bind them. But any other controls you add won't be bound.

    This is necessary because you can have any number of binding sources on a form. So there is no automatic assumption that the controls bind to any particular binding source.

    Hope this helps.

    • Proposed as answer by DeborahKMVP Tuesday, April 14, 2009 3:51 PM
    • Marked as answer by Kira Qian Friday, April 17, 2009 5:57 AM
    Monday, April 13, 2009 4:48 PM
  • Hi ASK Florida,

    To retrieve data from database, you can use SqlDataAdapter and fill the result to a DataTable or DataSet.

    SqlDataAdapter Class
    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

    Connecting and Retrieving Data in ADO.NET
    http://msdn.microsoft.com/en-us/library/ms254937(VS.80).aspx

    After ensure that you have get all the data you want from database correctly. you can bind them to some data controls such as TextBox, ComboBox, DataGridView. Or just assign the value to the TextBox control, do not use databinding.

    DataBinding
    http://www.codeproject.com/KB/database/databindingconcepts.aspx

    Sincerely,
    Kira Qian


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Kira Qian Friday, April 17, 2009 5:57 AM
    Wednesday, April 15, 2009 5:48 AM