Results 1 to 8 of 8

Thread: how do u?

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2002
    Location
    Dgte. City
    Posts
    45

    Question how do u?

    hi,
    i was wondering how do u get a specific field of one row in a database..

    example : (database)

    Number Name address
    1 mark dgte city
    2 jeni manila
    3 jorge pampangga

    wen dis is loaded to a datagrid or a combox.and u click one row(ex. 2nd row). how do u get a specific field like "address" into a textbox?


    p.s. could u give me a example of a connection string from a access database.




    thanks
    Mark_V

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Connection string (from memory, offhand):
    Provider=Microsoft.Jet.OleDb.4.0;Data Source="C:\myDB.mdb"

    Can't tell you how to get just one result w/o seeing how you're coding it. You could get it from a dataset or through SQL. Post some code.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2002
    Location
    Dgte. City
    Posts
    45
    ill just show u a vb 6 code and could u tell me how to do it in vb.net

    example:

    Private Sub DataGrid1_Click()
    text1.text = rs!name
    End Sub

    i want to get value of one field in a row that is currently selected.
    Mark_V

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can access the current row via the BindingManagerBase object. It shouldbe something like this:
    VB Code:
    1. Dim curRow As DataRowView = CType(DataGrid1.BindingContext.Item(DataGrid1.DataSource).Current, DataRowView)
    2.         txtName.Text = curRow("name")
    3.         txtValue.Text = curRow("value")

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I forget the exact syntax, vb's at work, but for a datagrid you could click the desired cell and use dg1.currentcell.value as well (may be off on that a bit).
    A combobox, as far as I know, can only have one item displayed. That would be cbo1.selecteditem, unless you were displaying one thing (a name, for example), but wanted the selection to return an associated value (ID, e.g.). In that case, use cbo1.selectedvalue - but you have to set the cbo1's valuemember to ID first to do that.
    Also, always take Edneiss's advice over mine.
    This link is a MSDN site that, besides letting you get a free copy of VB.Net Standard, has some good videos on common questions. It's pretty handy as a "show me" walkthrough intro to a lot of tasks.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2002
    Location
    Dgte. City
    Posts
    45
    thanks so much.

    last question. is there like a boundcolumn(like in vb6) wen using a combobox? where u can display a name and hide the primary key. so that wen u want to get the primary key u just call text1.text = combox1.boundtext.
    Mark_V

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    BoundColumn is SelectedValue now. Its like salvelinus said set the DisplayMember to the property or field to show as text and the ValueMember to the one to use as the value.

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    VB Code:
    1. 'Assumes you have a table with fields ID and Name,
    2. 'and have filled a dataset with those records,
    3. 'and bound cboMyCombo to the correct table
    4. With cboMyCombo
    5.    .DisplayMember = "Name"   'this is what user sees in combobox
    6.    .ValueMember = "ID"    'this is what's returned when user selects a name
    7. End with
    8. .
    9. .
    10. .
    11. 'User clicks a choice
    12. cboMyCombo_SelectedIndexChanged( ByVal .....)   'event handler
    13.    dim lngID As Long   'assumes ID fiels is a Long value - change if needed.
    14.    'Long is default for Access autonumber
    15.  
    16.    lng ID = cboMyCombo.SelectedValue   'returns ID
    17.    'do what you want with this value
    18. End Sub
    Last edited by salvelinus; May 16th, 2004 at 06:36 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
  •  



Click Here to Expand Forum to Full Width