[Mono-devel-list] Filling Datatable not working

Krieg Andreas Krieg.Andreas at OCE.DE
Fri Jun 18 01:52:05 EDT 2004


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040618/8b4f94fe/attachment.html 


More information about the Mono-devel-list mailing list