473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

c# datatable search help

77
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
Aug 9 '07 #1
4 2232
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
Aug 9 '07 #2
piercy
77
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...
Expand|Select|Wrap|Line Numbers
  1. toArray[a] = toArray[a].Replace("  ", " ");
  2. string[] newArray = toArray[a].Split(new char[]{' '});
  3. string str = "[AdmissionNumber] = " + newArray[2];
  4. DataRow[] drow = tblPupils.Select(str);
  5. pupilstr = drow["PersonID"].ToString();  //cannot convert string to int..
  6. //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
Aug 9 '07 #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...
Expand|Select|Wrap|Line Numbers
  1. toArray[a] = toArray[a].Replace("  ", " ");
  2. string[] newArray = toArray[a].Split(new char[]{' '});
  3. string str = "[AdmissionNumber] = " + newArray[2];
  4. DataRow[] drow = tblPupils.Select(str);
  5. pupilstr = drow["PersonID"].ToString();  //cannot convert string to int..
  6. //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
Aug 10 '07 #4
piercy
77
got this problem solved now. it was because i was using an arrway rather than an array list.
Aug 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: VMI | last post by:
We have this huge application that's based on storing tons of data on a dataTable. The only problem we're having is that storing LOTS of data (1 million records) into a datatable will slow down the...
3
by: Mico | last post by:
I would be very grateful for any help with the following problem: I use a DataAdapter to fill a DataSet in the Page_Load method. Later, I use this DataSet to construct a DataTable, then create...
2
by: pagates | last post by:
Hi All, I have a DataTable in a Windows Forms project that I would like to use a Select statement. The problem is, I'd like to be able to do wildcard searches (including single charcater...
4
by: Brett Romero | last post by:
I fill a DataTable with search results, which take a very long time if I first clear it. The values come from an object and I map them into the corresponding table columns. I may have 65000...
4
by: Rich | last post by:
Hello, I need to store various values that I will need to look up later on. I have been using hashtables and arraylists. But I can only store 2 items per row in a hashtable - key, value, and...
4
by: oopman2002 | last post by:
I have created a DataSet DataTable which is comprised of data from a number of sources. The resultant datatable is about 500,000 records and writing them out one at a time takes forever. Does...
2
by: MarkusJNZ | last post by:
Hi, I have a DataTable which I want split into two other datatables with the top 1/2 of the original datatable in one datatable and the other 1/2 in another datatable. Is there any easier way to...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
0
by: user1980 | last post by:
Hello Can somebody please help me with the paging in a grid-view. please find my code below SqlDataAdapter sda = new SqlDataAdapter(); DataTable dt = new DataTable(); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.