|
-
May 14th, 2004, 04:59 PM
#1
Thread Starter
Member
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
-
May 14th, 2004, 07:54 PM
#2
Frenzied Member
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.
-
May 15th, 2004, 01:27 AM
#3
Thread Starter
Member
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.
-
May 15th, 2004, 01:52 AM
#4
You can access the current row via the BindingManagerBase object. It shouldbe something like this:
VB Code:
Dim curRow As DataRowView = CType(DataGrid1.BindingContext.Item(DataGrid1.DataSource).Current, DataRowView)
txtName.Text = curRow("name")
txtValue.Text = curRow("value")
-
May 15th, 2004, 08:26 AM
#5
Frenzied Member
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.
-
May 16th, 2004, 01:47 AM
#6
Thread Starter
Member
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.
-
May 16th, 2004, 02:03 AM
#7
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.
-
May 16th, 2004, 06:28 AM
#8
Frenzied Member
VB Code:
'Assumes you have a table with fields ID and Name,
'and have filled a dataset with those records,
'and bound cboMyCombo to the correct table
With cboMyCombo
.DisplayMember = "Name" 'this is what user sees in combobox
.ValueMember = "ID" 'this is what's returned when user selects a name
End with
.
.
.
'User clicks a choice
cboMyCombo_SelectedIndexChanged( ByVal .....) 'event handler
dim lngID As Long 'assumes ID fiels is a Long value - change if needed.
'Long is default for Access autonumber
lng ID = cboMyCombo.SelectedValue 'returns ID
'do what you want with this value
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|