L
Lasse Edsvik
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.InvalidOperationException: Fill:
SelectCommand.Conne
ction property has not been initialized.
at System.Data.Common.DbDataAdapter.GetConnection3(DbDataAdapter adapter,
IDb
Command command, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand co
mmand, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Procent.DataJox.Northwind.GetAllCustomers() in C:\Documents and
Settings\A
dministrator\My Documents\Visual Studio\Projects\DataJox\DataJox\Class1.cs:
line 21
at rock.Program.Main(String[] args) in C:\Documents and
Settings\Administrato
r\My Documents\Visual Studio\Projects\DataJox\rock\Program.cs:line 14
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Procent.DataJox
{
public class Northwind
{
private SqlConnection dbconn;
public DataSet GetAllCustomers()
{
Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("CustListAll", dbconn);
da.Fill(ds);
return ds;
}
private void Open()
{
string connstr = "server=localhost;database=northwind;UID=sa;PWD=kk";
try
{
SqlConnection dbconn = new SqlConnection(connstr);
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.InvalidOperationException: Fill:
SelectCommand.Conne
ction property has not been initialized.
at System.Data.Common.DbDataAdapter.GetConnection3(DbDataAdapter adapter,
IDb
Command command, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand co
mmand, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Procent.DataJox.Northwind.GetAllCustomers() in C:\Documents and
Settings\A
dministrator\My Documents\Visual Studio\Projects\DataJox\DataJox\Class1.cs:
line 21
at rock.Program.Main(String[] args) in C:\Documents and
Settings\Administrato
r\My Documents\Visual Studio\Projects\DataJox\rock\Program.cs:line 14
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Procent.DataJox
{
public class Northwind
{
private SqlConnection dbconn;
public DataSet GetAllCustomers()
{
Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("CustListAll", dbconn);
da.Fill(ds);
return ds;
}
private void Open()
{
string connstr = "server=localhost;database=northwind;UID=sa;PWD=kk";
try
{
SqlConnection dbconn = new SqlConnection(connstr);
dbconn.Open();
}
catch
{
throw;
}
}
}
}