473,382 Members | 1,689 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,382 software developers and data experts.

Retrieving records from datatable

Hi,

Can anyone tell me how to retrieve record values from a datatable?.My requirement is like:

Within a for loop I am executing different stored procedures and storing records in a datatable so that i cannot specify paticular column names.i want to write the first row values of each result into a log file.(application is windows service)
Code is :

Expand|Select|Wrap|Line Numbers
  1. DataTable dtTransID = new DataTable(); 
  2. DBConnect(); 
  3. string sp=" exec "+storedProcedure+"  ";
  4. dtTransID =mDB.RunSp(sp);
  5. if(dtTransID.Rows.Count >0)
  6. {
  7. for(i=0;i<dtTransID.Rows.Count;i++)
  8. {
  9. if (storedProcedure!=null)
  10. {
  11. message = message + Datetime.Now+ "\n  + dtTransID.Rows[0] +, -  ";
  12. message = message + dtTransID.Rows[0] + ",";
  13. Globals.log.logMessage(message);
  14.  
  15. }
dtTransID.Rows[0] -This line is returning 'system.data.rows' not any records.
Please help me..
Thanks in advance
Oct 19 '08 #1
3 1157
kenobewan
4,871 Expert 4TB
Perhaps no rows are being returned from your stored procedure? You may also need a datareader.
Oct 19 '08 #2
Perhaps no rows are being returned from your stored procedure? You may also need a datareader.

No kenobewan...That count shows as 8.but its not reading the values.....
Oct 23 '08 #3
Plater
7,872 Expert 4TB
dtTransID.Rows[0] is a DataRow object, you are trying to use it as a string
if you only want the first column of the first row, try maybe:
dtTransID.Rows[0][0].ToString()
Oct 23 '08 #4

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

Similar topics

2
by: JC | last post by:
Hi, I have a database that imports 4 reports to my "data" table, each report has its own identifier. Then I have a table with Analysts with the report identifier that they are to be assigned to. ...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
3
by: suresh | last post by:
frenz, i need to disable the add new record mode in datarid. i just want to modify the existing records in the grid...but i dont want to add new records..how do i do that? -suresh
2
by: RSH | last post by:
I am struggling a bit trying to get at all of the Table names in a given Access database. I have the code below which should be retrieving the information...i am just having a bit of trouble...
6
by: AlveenX | last post by:
Hi, I am trying to pick a Guid from a data row using the following code: foreach(DataRow row in MyDataTable.Rows) { (Guid)row }
0
by: funky4you | last post by:
I am using a simple select query in C# app that fetches a row which has a datatime field. The query is simple "SELECT * FROM THE USERS WHERE USER_NAME = 'ABC' ", the users table contains a...
5
by: Nathan Sokalski | last post by:
I want to select only the first n records from a database using VB.NET. I have declared a DataTable and OleDB.OleDbDataAdapter as follows: Dim linkstable As New DataTable Dim linksadapter As New...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: xia0jie | last post by:
Hi all, Im using the following codes to retrieve records from excel file. OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Path + "; Extended...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.