newbie c# ado.net question.

D

DC

Any idea why the following code is giving me the error "CS0246: The type
or namespace name 'SeminarDataAdapter' could not be found (are you
missing a using directive or an assembly reference?)"

It looks like Ive declared an instance of the OleDataAdapter object type
for SeminarDataAdapter correctly.

Any ideas?

<script language="C#" runat="server">

void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack != true)
{
BindData();
}
}

void BindData()
{

OleDbConnection myConnection= new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\\Program Files\\Common

Files\\ODBC\\Data Sources\\seminars.mdb;");

///instantiate OleDbDataAdapter to create DataSet
OleDbDataAdapter SeminarDataAdapter = new OleDbDataAdapter("select *
from SeminarList",myConnection);

/// the following is for creating automatic command builder
OleDbCommandBuilder SeminarCmdBuilder = new
OleDbCommandBuilder(SeminarDataAdapter);

DataSet SeminarDataSet = new DataSet();

///fill the dataset
SeminarDataAdapter.Fill(SeminarDataSet, "SeminarList");

///set the dataset as a datasource for windows datagrid

datagrid1.DataSource = SeminarDataSet.Tables["SeminarList"].DefaultView;
datagrid1.DataBind();

}

void btnSave_Click(object sender, System.EventArgs e)
{
try
{
///the following statement
///inserts
///updates
///deletes for you
/// Without the CommandBuilder, this line would fail.

SeminarDataAdapter.UpdateCommand =
SeminarCmdBuilder.GetUpdateCommand();
SeminarDataAdapter.Update(SeminarDataSet);
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}

</script>

--
_______________________________________________

DC

"You can not reason a man out of a position he did not reach through reason"

"Don't use a big word where a diminutive one will suffice."

"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
 
C

ChrisM

I may be wrong, maybe I've missed somthing, but you seem to declare
'SeminarDataAdapter' inside of BindData()
That means it only exists within that Method.

You can't use it in a different method ('btnSave_Click') as it doesn't exist
in that method.

You need to declare 'SeminarDataAdapter' as a 'global' object (ie outside
the two methods) so that both methods can 'see' it.
 
P

pvdg42

DC said:
Any idea why the following code is giving me the error "CS0246: The type
or namespace name 'SeminarDataAdapter' could not be found (are you missing
a using directive or an assembly reference?)"

It looks like Ive declared an instance of the OleDataAdapter object type
for SeminarDataAdapter correctly.

Any ideas?

<script language="C#" runat="server">

void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack != true)
{
BindData();
}
}

void BindData()
{

OleDbConnection myConnection= new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Program
Files\\Common

Files\\ODBC\\Data Sources\\seminars.mdb;");

///instantiate OleDbDataAdapter to create DataSet
OleDbDataAdapter SeminarDataAdapter = new OleDbDataAdapter("select *
from SeminarList",myConnection);

/// the following is for creating automatic command builder
OleDbCommandBuilder SeminarCmdBuilder = new
OleDbCommandBuilder(SeminarDataAdapter);

DataSet SeminarDataSet = new DataSet();

///fill the dataset
SeminarDataAdapter.Fill(SeminarDataSet, "SeminarList");

///set the dataset as a datasource for windows datagrid

datagrid1.DataSource =
SeminarDataSet.Tables["SeminarList"].DefaultView;
datagrid1.DataBind();

}

void btnSave_Click(object sender, System.EventArgs e)
{
try
{
///the following statement
///inserts
///updates
///deletes for you
/// Without the CommandBuilder, this line would fail.

SeminarDataAdapter.UpdateCommand =
SeminarCmdBuilder.GetUpdateCommand();
SeminarDataAdapter.Update(SeminarDataSet);
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}

</script>
Which statement in your code is raising the error? Something in the
btnSave_Click method by chance?
 
C

Cor Ligthert [MVP]

DC,

In addition to the answer from ChrisM.

Beside that I see not the button handling that is needed by a Webform
datagrid but maybe did you not show that to us.

However more important your aspnet application is stateless. The last means
that you somewhere have to preserve your dataset. For me the best place for
that is the session. You have than to say in your save event something as

DataSet SeminairList = (DataSet) Session.item("SeminairListDataSet");

This you have to do in every action where you need it, as well do you have
to preserve it everytime at the end in the session (and not forget to bind
it to the datagrid everytime).

I am not sure of this, but I would create the commandbuilder just before the
update command and not direct before the fill.

I hope this helps,

Cor
 

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

Top