473,715 Members | 6,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving records from datatable

2 New Member
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.(applicati on 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.ro ws' not any records.
Please help me..
Thanks in advance
Oct 19 '08 #1
3 1166
kenobewan
4,871 Recognized Expert Specialist
Perhaps no rows are being returned from your stored procedure? You may also need a datareader.
Oct 19 '08 #2
preethadotnet
2 New Member
Perhaps no rows are being returned from your stored procedure? You may also need a datareader.

No kenobewan...Tha t count shows as 8.but its not reading the values.....
Oct 23 '08 #3
Plater
7,872 Recognized Expert Expert
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
2697
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. What I need to do is loop the two tables so that an Analyst is assigned to each record in the "data" table based on the identifier. For example, I have one analyst that needs to be assigned to the "H" report records, one analyst that needs to...
1
3894
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 = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
3
7110
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
6388
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 displaying the Table names out of the datatable. Thanks for any assistance you might be able to offer! Ron
6
19975
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
1153
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 datetime field , it is an oracle table This app works fine on my developmet pc , but on the user PC it gives the following error .I am using OLEDB Error Encountered: Specified argument was out of the range of valid values. Parameter name: Year, Month,...
5
2041
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 OleDb.OleDbDataAdapter("SELECT * FROM worldnews ORDER BY updated", System.Configuration.ConfigurationManager.AppSettings("connectionstring")) I want to use the Fill method, and I thought the following overload looked like it might work:
2
3682
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 different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc.. then,i have a datagrid...
1
1801
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 Properties='Excel 8.0;HDR=Yes;IMEX=1'"); OleDbCommand cmd = new OleDbCommand("SELECT TOP 10 * FROM WHERE <> ''", conn); DataSet ds = new DataSet(); da = new OleDbDataAdapter(cmd); da.Fill(ds);
0
8823
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.