[Mono-devel-list] Data Adapter problem

Daniel Morgan danielmorgan at verizon.net
Mon Jul 18 18:28:25 EDT 2005


Suresh filed a bug. He also fixed it in svn already.

Konstantin Triger wrote:

> Hello,
>
> Please file a bug in Bugzilla.
>
> Regards,
> Konstantin Triger
>
>
>
> Daniel Morgan wrote:
>
>> I have a problem with the data adapter on Mono 1.1.8 on Windows.  Has 
>> this been fixed in svn?
>>
>> Notice my test case does not use column nor table mappings.
>>
>> Results on Dot Net 1.1:
>>
>> E:\projects\DotNet\C#\TestSqlClientAdapter\bin\Debug>TestSqlClientAdapter.exe 
>>
>> Apapter Test Begin...
>> Insert...
>> Value 0: 3
>> Value 0: Value inserted
>> Rows retrieved: 1
>> Update...
>> Value 0: 3
>> Value 0: Value updated
>> Rows retrieved: 1
>> Delete...
>> Rows retrieved: 0
>> Done.
>>
>> Results on Mono 1.1.8 on Windows:
>>
>> E:\projects\DotNet\C#\TestSqlClientAdapter\bin\Debug>mono 
>> TestSqlClientAdapter.e
>> xe
>> Apapter Test Begin...
>> Insert...
>>
>> Unhandled Exception: System.IndexOutOfRangeException: 
>> DataColumnMappingCollectio
>> n doesn't contain DataColumnMapping with SourceColumn 'num_value'.
>> in <0x000cd> System.Data.Common.DataColumnMappingCollection:get_Item 
>> (System.Str
>> ing sourceColumn)
>> in (wrapper remoting-invoke-with-check) 
>> System.Data.Common.DataColumnMappingColl
>> ection:get_Item (string)
>> in <0x001eb> 
>> System.Data.SqlClient.SqlCommandBuilder:CreateInsertCommand (System
>> .Data.DataRow row, System.Data.Common.DataTableMapping tableMapping)
>> in (wrapper remoting-invoke-with-check) 
>> System.Data.SqlClient.SqlCommandBuilder:
>> CreateInsertCommand 
>> (System.Data.DataRow,System.Data.Common.DataTableMapping)
>> in <0x00197> 
>> System.Data.SqlClient.SqlCommandBuilder:RowUpdatingHandler (System.
>> Object sender, System.Data.SqlClient.SqlRowUpdatingEventArgs e)
>>
>>
>> Here is the test case:
>>
>> using System;
>> using System.Data;
>> using System.Data.Common;
>> using System.Data.SqlClient;
>>
>> namespace TestSqlClientAdapter {
>>    public class Test {
>>        static SqlConnection con;
>>        static SqlTransaction trans;
>>
>>        public static void Main (string[] args)
>>        {
>>            Console.WriteLine("Apapter Test Begin...");
>>            con = new 
>> SqlConnection("server=localhost;database=pubs;user 
>> id=sa;password=mypass");
>>            con.Open();
>>                      Setup();
>>
>>            trans = con.BeginTransaction();
>>            Insert();
>>            trans.Commit();
>>
>>            trans = con.BeginTransaction();
>>            Update();
>>            trans.Commit();
>>
>>            trans = con.BeginTransaction();
>>            Delete();
>>            trans.Commit();
>>
>>            con.Close();
>>            Console.WriteLine("Done.");
>>        }
>>
>>        static void Setup()
>>        {
>>            SqlCommand cmd = con.CreateCommand();
>>            cmd.Transaction = trans;
>>            cmd.CommandText = "DROP TABLE MONO_TEST_ADAPTER1";
>>
>>            try { cmd.ExecuteNonQuery();
>>            } catch(SqlException e) { }
>>
>>            cmd.CommandText =
>>                "CREATE TABLE MONO_TEST_ADAPTER1 (" +
>>                " num_value int primary key," +
>>                " txt_value varchar(64))";
>>            cmd.ExecuteNonQuery();
>>
>>            cmd.Dispose();
>>            cmd = null;
>>        }
>>
>>        static void Insert()
>>        {
>>            Console.WriteLine("Insert...");
>>
>>            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM 
>> MONO_TEST_ADAPTER1", con);
>>            adapter.SelectCommand.Transaction = trans;
>>            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
>>                      DataSet ds = new DataSet();
>>            adapter.Fill(ds,"MONO_TEST_ADAPTER1");
>>                      DataRow row = 
>> ds.Tables["MONO_TEST_ADAPTER1"].NewRow();
>>            row["num_value"] = 3;
>>            row["txt_value"] = "Value inserted";
>>
>>            ds.Tables["MONO_TEST_ADAPTER1"].Rows.Add(row);
>>
>>            adapter.Update(ds, "MONO_TEST_ADAPTER1");
>>
>>            row = null;
>>            builder = null;
>>            adapter = null;
>>            ds = null;
>>                      ReadData(con, "SELECT * FROM MONO_TEST_ADAPTER1");
>>        }
>>
>>        static void Update()
>>        {
>>            Console.WriteLine("Update...");
>>
>>            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM 
>> MONO_TEST_ADAPTER1", con);
>>            adapter.SelectCommand.Transaction = trans;
>>            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
>>                      DataSet ds = new DataSet();
>>            adapter.Fill(ds,"MONO_TEST_ADAPTER1");
>>                      DataRow row = 
>> ds.Tables["MONO_TEST_ADAPTER1"].Rows[0];
>>            row["txt_value"] = "Value updated";
>>
>>            adapter.Update(ds, "MONO_TEST_ADAPTER1");
>>
>>            row = null;
>>            builder = null;
>>            adapter = null;
>>            ds = null;
>>
>>            ReadData(con, "SELECT * FROM MONO_TEST_ADAPTER1");
>>
>>        }
>>
>>        static void Delete()
>>        {
>>            Console.WriteLine("Delete...");
>>
>>            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM 
>> MONO_TEST_ADAPTER1", con);
>>            adapter.SelectCommand.Transaction = trans;
>>            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
>>                      DataSet ds = new DataSet();
>>            adapter.Fill(ds,"MONO_TEST_ADAPTER1");
>>                      ds.Tables["MONO_TEST_ADAPTER1"].Rows[0].Delete();
>>
>>            adapter.Update(ds, "MONO_TEST_ADAPTER1");
>>
>>            builder = null;
>>            adapter = null;
>>            ds = null;
>>
>>            ReadData(con, "SELECT * FROM MONO_TEST_ADAPTER1");
>>
>>        }
>>
>>        private static void ReadData(IDbConnection con, string sql)
>>        {
>>            IDbCommand cmd = con.CreateCommand();
>>            cmd.Transaction = trans;
>>            cmd.CommandText = sql;
>>            IDataReader reader = cmd.ExecuteReader();
>>            int rows = 0;
>>            while(reader.Read()) {
>>                Console.WriteLine("Value 0: {0}", reader[0]);
>>                Console.WriteLine("Value 0: {0}", reader[1]);
>>                rows++;
>>            }
>>            Console.WriteLine("Rows retrieved: {0}", rows);
>>            reader.Close();
>>            reader = null;
>>            cmd.Dispose();
>>            cmd = null;
>>        }
>>    }
>> }
>>
>>
>>
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list