Adapter Fill doesn't work

37 views
Skip to first unread message

samoht

unread,
Nov 5, 2008, 10:25:49 AM11/5/08
to H2Sharp
Adapter.Fill crashes with an exception
Reading the data with execute reader works

// Open Connection
var fbConnection = new H2Connection(@"jdbc:h2:d:
\h2","sa",null);
fbConnection.Open();
var command = fbConnection.CreateCommand();
command.CommandText = @"CREATE TABLE STRN007
(
TRN007001 Varchar(20)
);";
command.ExecuteNonQuery();

var rnd = new Random();
var transaction = fbConnection.BeginTransaction();

for (int i = 0; i < 40000; i++)
{
using (command = fbConnection.CreateCommand())
{
command.Transaction = transaction;
command.CommandText = string.Format("INSERT INTO
STRN007 (TRN007001) VALUES (\'{0}\')", rnd.NextDouble());
command.ExecuteNonQuery();
}
}

transaction.Commit();


var dataTable = new DataTable();
using(var adapter = new H2DataAdapter("Select * from
STRN007", fbConnection))
{
adapter.Fill(dataTable);
}

Jonathan Porter

unread,
Nov 6, 2008, 1:30:01 AM11/6/08
to h2s...@googlegroups.com
What is the exception being thrown?

--
Sent from my mobile device

Jonathan Porter

unread,
Nov 6, 2008, 1:32:42 AM11/6/08
to h2s...@googlegroups.com
The full stack trace and error message and that of any inner exceptions.

On 11/5/08, samoht <thomas....@gmail.com> wrote:
>

--

samoht

unread,
Nov 6, 2008, 3:57:20 AM11/6/08
to H2Sharp
This is the call stack

System.NotSupportedException: Only CommandBehavior Default is
supported for now.
at System.Data.H2.H2Command.ExecuteReader(CommandBehavior behavior)
in C:\H2Sharp-Release\\H2Sharp\\H2Command.cs:line 387
at System.Data.H2.H2Command.ExecuteDbDataReader(CommandBehavior
behavior) C:\in H2Sharp-Release\\H2Sharp\\H2Command.cs:line 374
at
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables,
Int32 startRecord, Int32 maxRecords, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at EmbeddedFirebirdExample.Form1.button1_Click(Object sender,
EventArgs e) in Form1.cs:line 93

the reason is this method:

public new H2DataReader ExecuteReader(CommandBehavior behavior)
{
if (behavior != CommandBehavior.Default) { throw new
NotSupportedException("Only CommandBehavior Default is supported for
now."); }
CheckConnection();
EnsureStatment();
try
{
return new H2DataReader(statement.executeQuery());
}
catch(org.h2.jdbc.JdbcSQLException ex)
{
throw new H2Exception(ex);
}
}

I changed it to following:

public new H2DataReader ExecuteReader(CommandBehavior behavior)
{
CheckConnection();
EnsureStatment();
try
{
ResultSet set = statement.executeQuery();
if
((behavior&CommandBehavior.SingleResult)==CommandBehavior.SingleResult)
{
set.next();
}
return new H2DataReader(statement.executeQuery());
}
catch(org.h2.jdbc.JdbcSQLException ex)
{
throw new H2Exception(ex);
}
}

Now it works but i don't know if this is correct

samoht

unread,
Nov 6, 2008, 4:02:18 AM11/6/08
to H2Sharp
The function below works now

public new H2DataReader ExecuteReader(CommandBehavior behavior)
{
CheckConnection();
EnsureStatment();
try
{
ResultSet set = statement.executeQuery();
if
((behavior&CommandBehavior.SingleResult)==CommandBehavior.SingleResult)
{
set.next();
}
return new H2DataReader(set);

Jonathan Porter

unread,
Nov 10, 2008, 1:56:40 PM11/10/08
to h2s...@googlegroups.com
So this works for sure? You don't loose a record by calling next?

--

Reply all
Reply to author
Forward
0 new messages