ADO Error

D

Dave Bailey

When I execute the following code on a WebForm I get the
following message:

Object reference not set to an instance of an object.

This error occurs at the dataConnection.ConnectionString
command.

public void OpenWorkorder()
{
string connStr
= "Provider=MSDAORA.1;User ID=maximo;Data
Source=Demo;Password=xxxxxx";
dataConnection.ConnectionString =
connStr;
dataConnection.Open();

string strSelect = "Select Wonum
from Workorder where Wonum =" + workorderText.Text;
dataCommand.Connection =
dataConnection;
dataCommand.CommandText =
strSelect;
dataCommand.ExecuteReader();

while (dataReader.Read())
{
string Wonum =
dataReader.GetString(1);
wonumLabel.Text = Wonum;
}
dataReader.Close();
dataConnection.Close();

If anyone could help, Please

Dave
 
C

Carlson Quick

Dave Bailey said:
When I execute the following code on a WebForm I get the
following message:

Object reference not set to an instance of an object.

This error occurs at the dataConnection.ConnectionString
command.

public void OpenWorkorder()
{
string connStr
= "Provider=MSDAORA.1;User ID=maximo;Data
Source=Demo;Password=xxxxxx";
dataConnection.ConnectionString =
connStr;
dataConnection.Open();

string strSelect = "Select Wonum
from Workorder where Wonum =" + workorderText.Text;
dataCommand.Connection =
dataConnection;
dataCommand.CommandText =
strSelect;
dataCommand.ExecuteReader();

You are never initializing the data reader, you nead something more like
this here
SqlDataReader dataReader = dataCommand.ExecuteReader();
 
R

Ryan Lee

Dave,

You have to initialize the dataConnection object. If it
is a OleDbConnection object using the System.Data.OleDb
namespace you would reference it this way in C#:

OleDbConnection dataConnection = new OleDbConnection();

Then do all the rest of it. Remember C# is object
oriented so almost every object has to be initialized.

Regards,

Ryan
 
G

Guest

This works just as it should

Many Thanks,

Dave
-----Original Message-----
Dave,

You have to initialize the dataConnection object. If it
is a OleDbConnection object using the System.Data.OleDb
namespace you would reference it this way in C#:

OleDbConnection dataConnection = new OleDbConnection();

Then do all the rest of it. Remember C# is object
oriented so almost every object has to be initialized.

Regards,

Ryan

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

About SQLDataReader 5
Dynamic DataGrid Problem 2

Top