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

DataTable.Load gets blanks

george1106
Hi. I have a little trouble here.

when I use a IDataReader to get info from a DataBase, and try to put it into a DataTable (C#), I just get blanks. I have spaces for all the recods in the tabla where the reader comes from, buy I don't have data.

Any help will be appreciate.
Thanks
Feb 17 '07 #1
4 1256
kenobewan
4,871 Expert 4TB
Please post the relevant code...
Feb 19 '07 #2
Expand|Select|Wrap|Line Numbers
  1. /* these are my declarations: */
  2.         /// <summary>
  3.         /// conection to db
  4.         /// </summary>
  5.         private IDbConnection conexion = null;
  6.         /// <summary>
  7.         /// command used in multiple queryes
  8.         /// </summary>
  9.         private IDbCommand command = null;
  10.         /// <summary>
  11.         /// reader to hold data
  12.         /// </summary>
  13.         protected IDataReader reader;
  14.  
  15. /* i make de read in this function: */
  16. // cadena is the SQL sentence with wich I make the query
  17.  
  18.         protected bool LeerDeBDTR(string cadena)
  19.         {
  20.             if (conexion.State == ConnectionState.Open)
  21.             {
  22.                 this.command = this.conexion.CreateCommand();
  23.                 this.command.CommandType = CommandType.Text;
  24.                 command.CommandText = cadena;
  25.                 reader = command.ExecuteReader(CommandBehavior.Default);
  26.                 return true;
  27.             }
  28.             return false;
  29.         }
  30.  
  31. /* and here is where I try to load data from datareader to dataTable */
  32.  
  33. private DataSet LlenarDataSet(DataSetMaker maker, string tabla, string cadenaDeConsulta)
  34.         {
  35.             DataTable aux = new DataTable(tabla);
  36.             reader = null;
  37.             if (this.LeerDeBDTR(cadenaDeConsulta))
  38.             {
  39.                 if (reader.FieldCount > 0)
  40.                     aux.Load(reader);
  41.                 maker.Datos.Tables.Add(aux);
  42.             }
  43.             reader.Close();
  44.             return maker.Datos;
  45.         }
  46.  
  47. /* the DataSetMaker is only a container for the dataSet. */
  48.  
  49.     class DataSetMaker
  50.     {
  51.         DataSet dsDatos;
  52.         /// <summary>
  53.         /// Constructor principal
  54.         /// </summary>
  55.         /// <param name="nombre">nombre del DataSet</param>
  56.         public DataSetMaker(string nombre)
  57.         {
  58.             dsDatos = new DataSet();
  59.             dsDatos.DataSetName = nombre;
  60.         }
  61.         /// <summary>
  62.         /// Get. DataSet para uso externo
  63.         /// </summary>
  64.         public DataSet Datos
  65.         {
  66.             get
  67.             {
  68.                 return dsDatos;
  69.             }
  70.         }
  71.         /// <summary>
  72.         /// Crea una tabla en el data set
  73.         /// </summary>
  74.         /// <param name="nombre">nombre de la tabla</param>
  75.         public void CreateTabla(string nombre)
  76.         {
  77.             if (!dsDatos.Tables.Contains(nombre))
  78.                 dsDatos.Tables.Add(nombre);
  79.         }
  80.    }
thanks in advance.
Feb 19 '07 #3
kenobewan
4,871 Expert 4TB
I believe that your problem of not returning the data relates the return true after the execute reader and then you set the reader to null. How is the data getting from your execute statement to the datareader and table? Also I believe that trying to use your datareader in a separate function doesn't help...

Here is an article that may help:
DataReader made simple
or use a dataset:
Dynamic Database Creation - 2
Feb 21 '07 #4
thank you. it helped a lot :D
Feb 26 '07 #5

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

Similar topics

2
by: John A Grandy | last post by:
anyone know why this is ? Imports System.Data Imports System.Diagnostics Public Class WebForm12
7
by: Raymond Lewallen | last post by:
Which would be the proper way or the reason for using any of the following or combinations of the following? These are the 3 ways I've figured I can do what I want to do, I just don't know which...
1
by: tom c | last post by:
I am using Visual Web Developer 2005 Express Edition. I created a SQLDataSource just by draging the control to the form and filling in the blanks in the wizard. In code I need to use the...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.