[Mono-devel-list] SqlClient - DataSet stange behavior

Miguel Bazzano mbazzano at dirinfo.unt.edu.ar
Thu Aug 12 13:31:10 EDT 2004


Hi,
 
I am fairly new to mono but not to .net. I don't know if this is the correct
list to post to, but anyway.

 
Here is my problem:

In the following short program (at the end of the message) the DataSet loop
does not work, i.e.: the Fill command of the SqlDataAdapter does not put any
rows into the dataset, leaving and empy Rows collection, the data however is
there as the DataReader part works perfectly (in fact I only included it to
test that I have access to the data). What is stranger is the fact that this
happen with only some databases, I tried both the Northwind and Pubs
databases and they don't have the same behavior (they work ok with both
methods). Of course both methods work ok from .NET under Windows with all
databases. I tried compiling under windows and Linux Fedora 2 (Mono 1.0.1)
and the problem persists. 

Any help will be greatly appreciated as this is driving me crazy,

Regards,

Miguel Bazzano
 

Program Example:

using System;
using System.Data;
using System.Data.SqlClient;


class MainClass
{
	public static void Main(string[] args)
	{
		Console.WriteLine("Prueba desde linux");
		
		SqlConnection cnn1 = new SqlConnection("Data
Source=olap;UID=sa;PWD=xxx;Initial Catalog=Usuarios");
		cnn1.Open();
		Console.WriteLine(cnn1.State);
		DataSet dat = new DataSet();
		SqlCommand cmd = new SqlCommand("select top 100 * from
usuarios",cnn1);		

		SqlDataReader datr = cmd.ExecuteReader();
		Console.WriteLine(datr.RecordsAffected);
		Console.ReadLine();
		while (datr.Read())
		{
			Console.WriteLine(datr.GetValue(1));
		}
		//Works OK
		datr.Close();
		
		Console.ReadLine();
		
		System.Data.SqlClient.SqlDataAdapter dta = new
SqlDataAdapter(cmd);
		System.Data.DataTable dt = new DataTable();
		dta.Fill(dat);
		Console.WriteLine(dat.Tables.Count); //Returns 1
		Console.WriteLine(dat.Tables[0].Rows.Count); //Returns 0
		//dat.Tables[0].Rows.Add(
		Console.ReadLine();
		foreach (DataRow dr in dat.Tables[0].Rows)
		{
			Console.WriteLine(dr[1]);
		}
		
		cnn1.Close();
		
		
	}
}




More information about the Mono-devel-list mailing list