c# datatable search help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • piercy
    New Member
    • Aug 2007
    • 77

    c# datatable search help

    i need to extract a value from a datatable. in the datatable there are two values ID and AdmissionNumber . i have the admission number but i need to get the id number from the table. how would i be able to search the datatable and extract the ID number?

    i need it in some sort of loop because it will eventually be pulling multiple id's out depending on user input. is a shame you cant use SQL with datatables... SELECT ID FROM datatable WHERE AdmissionNumber == 'variable'

    hopefully that will give you the idea of what i need.

    thanks,
    Piercy
  • gyanendar
    New Member
    • Jun 2007
    • 90

    #2
    Originally posted by piercy
    i need to extract a value from a datatable. in the datatable there are two values ID and AdmissionNumber . i have the admission number but i need to get the id number from the table. how would i be able to search the datatable and extract the ID number?

    i need it in some sort of loop because it will eventually be pulling multiple id's out depending on user input. is a shame you cant use SQL with datatables... SELECT ID FROM datatable WHERE AdmissionNumber == 'variable'

    hopefully that will give you the idea of what i need.

    thanks,
    Piercy
    Hi
    If you are getting multiple id means there are repetition of id .Becase there would be only one id fetched in absance of repetition.
    Other case could be like "%...".In this multiple id would be fetched.So handle this case it would be better if u display the result in some gridview as fetch result in dataset or datatable.

    Regards

    Comment

    • piercy
      New Member
      • Aug 2007
      • 77

      #3
      no im not getting multiple id's theres actually two id columns with different values. my code already gets the admission number for me so i just need to get the ID number so the rest of my program can extract me some data using the number.

      ive got as far as...
      Code:
      toArray[a] = toArray[a].Replace("  ", " ");
      string[] newArray = toArray[a].Split(new char[]{' '});
      string str = "[AdmissionNumber] = " + newArray[2];
      DataRow[] drow = tblPupils.Select(str);
      pupilstr = drow["PersonID"].ToString();  //cannot convert string to int..
      //pupilid = Convert.ToInt16(pupilstr);
      just a small bit of info. the toArray is an array of people with values like Surname Forname admissionnumber group thats the reason for the splitting up etc. newArray[2] is the addmission number and tblPupils is a already existing data table. the error im getting on this at the moment is

      Cannot implicitly convert type 'string' to 'int'

      but.. all of my variables are strings or datarows except for pupilid which i havent got to yet.
      also its in a for loop wich increments depending on how many values were selected previously( variable a).

      Thanks,
      Piercy

      Comment

      • gyanendar
        New Member
        • Jun 2007
        • 90

        #4
        Originally posted by piercy
        no im not getting multiple id's theres actually two id columns with different values. my code already gets the admission number for me so i just need to get the ID number so the rest of my program can extract me some data using the number.

        ive got as far as...
        Code:
        toArray[a] = toArray[a].Replace("  ", " ");
        string[] newArray = toArray[a].Split(new char[]{' '});
        string str = "[AdmissionNumber] = " + newArray[2];
        DataRow[] drow = tblPupils.Select(str);
        pupilstr = drow["PersonID"].ToString();  //cannot convert string to int..
        //pupilid = Convert.ToInt16(pupilstr);
        just a small bit of info. the toArray is an array of people with values like Surname Forname admissionnumber group thats the reason for the splitting up etc. newArray[2] is the addmission number and tblPupils is a already existing data table. the error im getting on this at the moment is

        Cannot implicitly convert type 'string' to 'int'

        but.. all of my variables are strings or datarows except for pupilid which i havent got to yet.
        also its in a for loop wich increments depending on how many values were selected previously( variable a).

        Thanks,
        Piercy
        In ur code ..
        pupilstr = drow["PersonID"].ToString(); //cannot convert string to int..
        //pupilid = Convert.ToInt16 (pupilstr);[/CODE]
        why r u not assigning pupilid with drow-PersonId

        Comment

        • piercy
          New Member
          • Aug 2007
          • 77

          #5
          got this problem solved now. it was because i was using an arrway rather than an array list.

          Comment

          Working...