-
December 9th, 2008, 08:48 AM
#1
Need help on concept (getting row numbers)
Hi again,
the further I develop my small helper tool, the more details I need to get along with.
My current problem:
I read the columns from a MDB file and display them in some textboxes in the Form.
Since the MDB file has some few rows, the main entry with the name is displayed in a treeview like this:
MDB:
ID | Name | Info
---------------------
1 | Test | Info1
2| TestA | Info2
3 | TestB | Info3
GUI (treeview):
|---Test
|---TestA
|---TestB
Depending on the treeviews selection I change the content of the textboxes.
I do this so far by retrieving the SelectedNode.Index and look up the MDB for WHERE ID = index.
This works fine.
But I need a way to be independent of the SelectedNode.Index, cause I will implement some
filters so the treeview contains not all available entries and the indexes will be messed up.
How can I figure out the ID (or the row number) depending of a given Name (second column from MDB).
For example: I want the ID from 'TestA'. How can I do this?
I cannot use reader.GetString(0); to get the autonumbered values from "ID". It does not work. The very first valid column I can access is "Name" by reader.GetString(1) :-(
Some hints?
-
December 9th, 2008, 12:27 PM
#2
Re: Need help on concept (getting row numbers)
You should use GetInt32 (0) because the ID columns seems to be an integer not a string.
-
December 9th, 2008, 10:04 PM
#3
Re: Need help on concept (getting row numbers)
the node has a Tag property to store some information, you may use that to store the corresponding ID from your MDB.
hth
Busy
-
December 9th, 2008, 10:29 PM
#4
Re: Need help on concept (getting row numbers)
sample vb code:
Code:
Dim dt As New DataTable()
Using cn As New OleDbConnection("<Connection string>")
cn.Open()
Using cm As OleDbCommand = cn.CreateCommand()
cm.CommandType = CommandType.Text
cm.CommandText = "SELECT ID, [Name] FROM [<Table name>]"
Using rd As OleDbDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
dt.Load(rd)
rd.Close()
End Using
End Using
End Using
For Each dr As DataRow In dt.Rows
treeView1.Nodes.Add(dr("Name").ToString()).Tag = dr("ID").ToString()
Next
and to get the corresponding ID from the selected node to be passed on to the command parameter:
Code:
cm.Parameters("@ID").Value = Convert.ToInt32(treeView1.SelectedNode.Tag)
hth
Busy
-
December 10th, 2008, 12:06 AM
#5
Re: Need help on concept (getting row numbers)
thanks to all,
getting Int32(0) worked fine. I do not know why I solved this issue not by my own :-/
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
|