locked
TextBox (multiple line) & Databinding RRS feed

  • Question

  • In an attempt to do a project recently, I've bumped into a problem with textbox and databinding. I have a multiple line textbox and wish to display the address of a company. However the full address of the company is stored in multiple columns inside my database. When implemented, I can only display the street address onto my textbox. I'm currently databinding the textbox to the address field in my customer table. Is there a way to display more than one database column onto a textbox? Perhaps bind more than one piece of data to the textbox?

    Thanks

    Sunday, January 8, 2006 4:30 PM

Answers

  • hi,

    the problem lies within your dataset, this code for the binding source not the combobox

    if you want to select the record from the combobox it will be different code you will deal with your dataset, or your database

    in the top of your code view you will find 2 combobox at top select your binding source at left side and positionchanged at right side it will add a new sub to your code put this code in that sub it will looks exactly like that

    Private Sub TblcustomerBindingSource_PositionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblcustomerBindingSource.PositionChanged

    Me.TextBox2.Text = Me.TblcustomerBindingSource.Current("Address") & "," & Me.TblcustomerBindingSource.Current("City") & ", " & Me.TblcustomerBindingSource.Current("State") & " " & Me.TblcustomerBindingSource.Current("Zip")

    End Sub

    if something changed in that code it will not work properly

    hope it helps

    Monday, January 9, 2006 2:34 AM

All replies

  • hi,

    there are many ways to do that , the best way in my opinion to join the columns in one query column and to bind your data to the query not the table directly

    Hope it helps

    Sunday, January 8, 2006 4:40 PM
  • Another way to do it is using object binding. Both methods are a little more complex than straightforward binding to a datatable. Also, you should realize that it's only possible to read the data in this manner, you can't write back...well you could but it'd be simpler to create a separate edit form that separates the fields.
    Sunday, January 8, 2006 4:55 PM
  • And precisely how would you be able to bind my data to the query/object and not the table in VB 2005 express?
    Sunday, January 8, 2006 8:54 PM
  • hi,

    simply open your dataset in design view and right click and select add query and follow the wizard you can build your query as  sql statment, or stored procedure.

    as sql statment its like that:

    SELECT  [Column1] & " " & [Column2] AS MyAddress
    FROM AddressTable;

    i've tried to make it right now but  select with returned rows was not enabled i don't know why? may be its not active in express edition

    May be there are a way to do that as stored procedure unfortunatly i don't know much about stored procedures

    may be someone else can help in this

    Sunday, January 8, 2006 10:05 PM
  • Hi

    Thanks for replying so quickly. The main problem I'm still experiencing is how to tie the sql query and the textbox together. I've already created a query that retrives the street,city,state and zip from my table. But currently I don't know how to display it inside my textbox

     

    Sunday, January 8, 2006 11:49 PM
  • hi,

    my friend What i mean is that the query will join the columns together like "4 somewhat street in somewhat city" it will join the columns data as if its one column so that you can call that query

    ok my friend i'll tell you other way , its not the best but it works

    in your form designer

    1) don't bound your textbox to anything

    2) double click your binding source and  change the eventhandler to positionchanged  in code view

    Private Sub MyBindingSource_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBindingSource.PositionChanged

    'Dont bind your text box to anything

    TextBox1.Text = MyBindingSource.Current("street") & ", " & MyBindingSource.Current("city")  & ", " & MyBindingSource.Current("State") & ", " & MyBindingSource.Current("zipcode")

    End Sub

    hope it helps

    Monday, January 9, 2006 1:27 AM
  • Hi shakalama,

    Thank you for your tip, the textbox is now able to display the whole address. However whenever I choose the company from a comboBox, it doesn't display the correct address.

    Here's part of the code:

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    Me.TextBox2.Text = Me.TblcustomerBindingSource.Current("Address") & "," & Me.TblcustomerBindingSource.Current("City") & ", " & Me.TblcustomerBindingSource.Current("State") & " " & Me.TblcustomerBindingSource.Current("Zip")

     

    End Sub

    I suspect the problem lies within the Current function not being able to detect which choice is made by the comboBox1. This was never a problem before because I bound the textbox to the address field, and so whenever the index is changed inside comboBox1, the address field changes dynamically inside textBox2.

    Monday, January 9, 2006 2:15 AM
  • hi,

    the problem lies within your dataset, this code for the binding source not the combobox

    if you want to select the record from the combobox it will be different code you will deal with your dataset, or your database

    in the top of your code view you will find 2 combobox at top select your binding source at left side and positionchanged at right side it will add a new sub to your code put this code in that sub it will looks exactly like that

    Private Sub TblcustomerBindingSource_PositionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblcustomerBindingSource.PositionChanged

    Me.TextBox2.Text = Me.TblcustomerBindingSource.Current("Address") & "," & Me.TblcustomerBindingSource.Current("City") & ", " & Me.TblcustomerBindingSource.Current("State") & " " & Me.TblcustomerBindingSource.Current("Zip")

    End Sub

    if something changed in that code it will not work properly

    hope it helps

    Monday, January 9, 2006 2:34 AM
  • The code now work the way I want to. Thank you shakalama for your swift responses. Couldn't of done it without you.
    Monday, January 9, 2006 2:46 AM
  • hi, JinMaster

    you are most welcome my friend

    Monday, January 9, 2006 4:52 PM
  • How about using a textbox to submit to a SQL DB? I am trying to make a way for the user to report information into the database so the techs can find/receive the info they need (this is for Visual Web)... I know how to bind to a database using Visual Basic... but not ASP.NET using a textbox... Also The detailsview can submit but i want to use the textbox and dropdown options. this way the user can click the link to the menu and have the form there with my validation and the options they are allowed to choose from... anyone have any sugestions..
    Saturday, January 14, 2006 9:25 PM
  • hi,

    you can review those links for data access

    http://msdn2.microsoft.com/en-us/library/ms184649.aspx

    http://msdn.microsoft.com/vbasic/reference/data/default.aspx?pull=/library/en-us/dnsql90/html/mandataaccess.asp#mandataac_topic5

    http://www.connectionstrings.com/

     you will use the same code to connect to your database in asp.net

    you can access to your asp controls by useing the id of this control as long as it has id you can  use that id to assign or change values to it programaticlly

    i don't know much about detailsview

     

    hope that helps

    Saturday, January 14, 2006 10:41 PM