[Mono-devel-list] Filling Datatable not working

S Umadevi sUmadevi at novell.com
Fri Jun 18 05:22:27 EDT 2004


Hi
  I am not able to replicate the problem with your test program. I ran it across a sample database and I got the correct number of rows.
Can you please let me know if I there is any more information, am I missing anything in the setup..

Can you also try to check it again with the latest dll and let me know if the problem exists.

Regards
Uma

>>> Krieg Andreas <Krieg.Andreas at OCE.DE> 6/18/2004 11:22:05 AM >>>
Hi,

 

This code works fine with MS.NET Runtime but with mono the datatable will
not be filled:

 

using System;

using System.Data;

using System.Data.SqlClient;

 

namespace cdbTest

{

      /// <summary>

      /// Zusammenfassung für Class1.

      /// </summary>

      class Class1

      {

            /// <summary>

            /// Der Haupteinstiegspunkt für die Anwendung.

            /// </summary>

            [STAThread]

            static void Main(string[] args)

            {

                  Console.WriteLine("Connecting");

                  SqlConnection myConnection = new
SqlConnection("server=localhost;database=customers;User
ID=<hidden>;Password=<hidden>");

                  SqlCommand myCommand = new SqlCommand("select * from
Kunden", myConnection);

                  myConnection.Open();

                  Console.WriteLine("Connected");

//                IDataReader dr;

//                dr =
myCommand.ExecuteReader(CommandBehavior.SingleResult);

//                Console.WriteLine("Reader Executed");

//                int cnt = 0;

//                while (dr.Read()) 

//                {

//                      cnt++;

//                      Console.WriteLine("Rec#" + cnt + " --> " +
String.Format("{0} {1} {2} {3} {4}", dr[0], dr[1], dr[2], dr[3], dr[4]));

//                      if(cnt >= 100)

//                           break;

//                }

//                dr.Close();

                  DataTable dt = new DataTable();

 

                  SqlDataAdapter myAdapter = new SqlDataAdapter();

                  myCommand.CommandType = CommandType.Text;

                  myAdapter.SelectCommand = myCommand;

                  myAdapter.Fill(dt);

 

                  Console.WriteLine("Number of Records " + dt.Rows.Count);

                  myConnection.Close();

                  Console.WriteLine("Connection closed");

                  Console.WriteLine("Press ENTER");

                  Console.ReadLine();

 

            }

      }

}

 

The (commented out) DataReader stuff is working as expected, but the
DataTable will not be filled. I also tried to fill a Dataset, but this
doesn't work too.

 

I read by the Sql DataProvider Page on the mono site, that filling a
datatable should work.

 

I used Mono Beta 3 on Windows and Mono Beta 2 on linux to check it out.

 

Thanks for help,

 

Andreas





More information about the Mono-devel-list mailing list