Hello
Im trying to create a simple testclass that connects to a db on localhost
and a method that returns a dataset. I get these errors:
Unhandled Exception: System.InvalidO perationExcepti on: Fill:
SelectCommand.C onne
ction property has not been initialized.
at System.Data.Com mon.DbDataAdapt er.GetConnectio n3(DbDataAdapte r adapter,
IDb
Command command, String method)
at System.Data.Com mon.DbDataAdapt er.FillInternal (DataSet dataset,
DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand co
mmand, CommandBehavior behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, Int32
startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet)
at Procent.DataJox .Northwind.GetA llCustomers() in C:\Documents and
Settings\A
dministrator\My Documents\Visua l Studio\Projects \DataJox\DataJo x\Class1.cs:
line 21
at rock.Program.Ma in(String[] args) in C:\Documents and
Settings\Admini strato
r\My Documents\Visua l Studio\Projects \DataJox\rock\P rogram.cs:line 14
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Sql Client;
namespace Procent.DataJox
{
public class Northwind
{
private SqlConnection dbconn;
public DataSet GetAllCustomers ()
{
Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = new SqlCommand("Cus tListAll", dbconn);
da.Fill(ds);
return ds;
}
private void Open()
{
string connstr = "server=localho st;database=nor thwind;UID=sa;P WD=kk";
try
{
SqlConnection dbconn = new SqlConnection(c onnstr);
dbconn.Open();
}
catch
{
throw;
}
}
}
}
Im trying to create a simple testclass that connects to a db on localhost
and a method that returns a dataset. I get these errors:
Unhandled Exception: System.InvalidO perationExcepti on: Fill:
SelectCommand.C onne
ction property has not been initialized.
at System.Data.Com mon.DbDataAdapt er.GetConnectio n3(DbDataAdapte r adapter,
IDb
Command command, String method)
at System.Data.Com mon.DbDataAdapt er.FillInternal (DataSet dataset,
DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand co
mmand, CommandBehavior behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, Int32
startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet)
at Procent.DataJox .Northwind.GetA llCustomers() in C:\Documents and
Settings\A
dministrator\My Documents\Visua l Studio\Projects \DataJox\DataJo x\Class1.cs:
line 21
at rock.Program.Ma in(String[] args) in C:\Documents and
Settings\Admini strato
r\My Documents\Visua l Studio\Projects \DataJox\rock\P rogram.cs:line 14
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Sql Client;
namespace Procent.DataJox
{
public class Northwind
{
private SqlConnection dbconn;
public DataSet GetAllCustomers ()
{
Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = new SqlCommand("Cus tListAll", dbconn);
da.Fill(ds);
return ds;
}
private void Open()
{
string connstr = "server=localho st;database=nor thwind;UID=sa;P WD=kk";
try
{
SqlConnection dbconn = new SqlConnection(c onnstr);
dbconn.Open();
}
catch
{
throw;
}
}
}
}
Comment