Help plz!

How do i read data on the same row but on a different column from a mdb file using visual basic studio 2005.

so far i got : somethingDataSet.Tables(NameofTable).Rows.Find("StudnetID").Item("Name")

For example:

student ID Name

1 John

2 Matt

So if user put 1 it then the name should be John. And if 2 it should be Matt. However everytime i put 2, it gives me John. Could you guys help me with it

Hey Dave, Could you help me Thank you in advance



Answer this question

Help plz!

  • rashe

    i serously dont need to add anything, i just need to read the data from that row that is it.

    here are my codes. maybe it will be more helpful.

    Private objConnection As OleDbConnection

    Private objCommand As OleDbCommand

    Private objDataAdapter As OleDbDataAdapter

    Private objDataSet As DataSet

    Private Sub Student()

    objDataAdapter = New OleDbDataAdapter

    objDataSet = New DataSet

    objDataAdapter.SelectCommand = objCommand

    objDataAdapter.Fill(objDataSet, "StudentTable")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    objConnection = New OleDbConnection(strConnectionString)

    objCommand = New OleDbCommand

    objCommand.CommandText = "StudentTable"

    objCommand.CommandType = CommandType.TableDirect

    objCommand.Connection = objConnection

    Call Student()

    objDataSet.Tables("StudentTable").Rows.Find("StudentID").Item("StudentName") (studentid is already define and is an input from the user. so from this point I am just getting the student id to get the student name value.)

    End Sub

    Plz help me.hic hic


  • TaegerD

    No you dont "Need" the .ToString() but in his/her example he/she had a string variable he/she was reading into so therefor the .ToString() was needed.

    To answer your question:
    To itterate(sp ) through your Rows you need to address which Row you want to read from i.e.:

    somethingDataSet.Tables(NameofTable).Rows(INDEX).Item("Name")

    Put the row number your looking for instead of the INDEX

  • Fdeveloper

    Dim ColumnValue As String = ds.Tables("TableName").Rows(RowNumber).Item("ColumnName").ToString



  • vaibhavsaxena17

    That is strange. I have managed to do this before in C# ... Perhaps related to your database The DataSet not picking up your Primary Keys

    Have you just tried adding the constraint to your DataTable object
    somethingDataSet.Tables(NameofTable).Constraints.Add()

  • Juvenn

    that is the same thing as saying:

    somethingDataSet.Tables(NameofTable).Rows.Find("StudentID").Item("NameColumn")

    but lol everytime i do that it will tell me that table doesnt have primary key even though my age column is a freaking primary key. i dont get it Samthing happened if i do it ur way.


  • Frank I. garcia

    Ok here is another solution...use the select method of the table object to return the row(s) you need:

    Dim drs as Datarow() = DataSet.Tables(NameOfTable).Select(StudentId = 2)

    Dim dr as datarow = drs(0)

    Dim ColumnValue as string = dr("Name").toString



  • Tryston02

    Thank you for your help. but i don't think putting an index is the most effcient way to do it. Because you have to run all kind of error checking. Could we just put like a select squl statment in there
  • rdrrichards

    Sure, I am just thinking outloud here :)
    I dont think you can query a DataTable like a regular database.

    What you could do though I think, is use the .Find function to retreive the DataRow your looking for and then you have all the columns to your disposal.

    Dim myRow As DataRow = somethingDataSet.Tables(NameofTable).Rows.Find("StudnetID");
    Dim myName As String = myRow("NameColumn");
    Dim myAddress As String = myRow("AddressColumn");

    Would that help

  • Glandorf

    Anyone could help me with this thanks
  • sparkymark75

    I dont think you really need the .ToString it would still give you the value. However you must somehow increment your rows number automatically, you can't just go back to your code and change the row number everytime. Would you mind helping me with that ty
  • Help plz!