can you hook up an OleDbDataAdapter to a DataGrid at design time

B

Bennett Haselton

I know how to hook up an OleDbConnection, an OleDbDataAdapter, a
DataSet, and a DataView to a DataGrid named dgUserList at run time:

string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\shared\\test-database.mdb";
string strSQL = "SELECT username as uname, password as pword FROM
wbuser;";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL,
objConnection);
objAdapter.Fill(objDataSet, "zquser");
DataView objDataView = new DataView(objDataSet.Tables["zquser"]);
dgUserList.DataSource=objDataView;
dgUserList.DataBind();

I'm trying to figure out how to do all of this at design time in VS
..Net 2002. I'm able to drop in the OleDbConnection object on the Web
Form and point it at the .mdb file. Then I'm able to create an
OleDbDataAdapter and when it asks me what data connection to use, I
specify the OleDbConnection representing the .mdb file and specify an
SQL query to get the data out of the table I want, and at the end, if
I press "preview data" it shows a table representing the data
correctly.

Also at design time, I can drop in a DataView called dvUserList and
then select the DataGrid and set the DataSource property to
dvUserList. I can also drop in a DataSet (called dsUnamesStuff) and
create a table in it called Table1, and then by selecting properties
of the DataView called dvUserList I can hit the "Table" dropdown and
it will show dsUnamesStuff->Table1 as a table that I can select.

The missing link is that I can't figure out how to bridge the gap
between the DataSet that is linked to my DataGrid, and the
OleDbDataAdapter that provides access to the data I want. I've taken
every line in the run-time code above, and found the design-time
equivalent, except for this one line:

objAdapter.Fill(objDataSet, "zquser");

Where in the design view of the adapter can I connect it to a table in
the dsUnamesStuff DataSet? If I select the dsUnamesStuff DataSet and
browse the "Tables" Collection properties, it lets me add and remove
new tables but it doesn't let me create any that are populated by the
OleDbDataAdapter. Or if I select the OleDbDataAdapter, I can't see
any editable properties that can connect it to the DataSet.

If anyone has time, I'm also confused about the "TableMappings" on the
OleDbDataAdapter. If I select the OleDbDataAdapter and click on the
button to edit its "TableMappings" properties, the dialog box that
opens says, "For each column in the source table, specify the name of
the corresponding column in the dataset table". What I don't
understand is what this sentence means by "the dataset". Since there
can be more than one DataSet declared in the code, and any of them can
be passed as an argument to the OleDbDataAdapter.Fill() method, what
does "the dataset" refer to at design time? Or does that just mean
that those column mappings will be applied whenever *any* DataSet is
passed at run time to the Fill() method.

Thanks very much for any help you have time to give me!

-Bennett
 
C

Cor Ligthert

Bennett,

A quiet long message. I do not know anymore how it exactly was in VB2002
because the OleDb part is changed in VB2003 so I tell it for VB2003 for what
I readed in your message it is maybe still the same.

You can select a Oledbdataadapter from your toolbox to your form. Than
starts a wizard that lets you tell the connection and the selectstring.
(This is the part I am in doubt if it was already in VB2002).

Than you can do a right click on that adapter that than is apeared bellow on
your form and generate the dataset.

You drag a dataview on your form; in the properties of that can be set the
databinding to the table you want to bind, watch for it that you set it to
the table and not to the dataset that is an often made error.

Than you can drag a datagrid on your form in which properties you can set
the databinding to the dataview.

I hope that what I have told about the table does answer as well your other
question about the dataset table. With the design method you are inclined to
make always datasets (although it is better that you use one, that can as
well using the designer). This means that you have to use the properiete
table from that dataset when you are doing things using the designer.

I hope this helps?

Cor

I know how to hook up an OleDbConnection, an OleDbDataAdapter, a
DataSet, and a DataView to a DataGrid named dgUserList at run time:

string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\shared\\test-database.mdb";
string strSQL = "SELECT username as uname, password as pword FROM
wbuser;";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL,
objConnection);
objAdapter.Fill(objDataSet, "zquser");
DataView objDataView = new DataView(objDataSet.Tables["zquser"]);
dgUserList.DataSource=objDataView;
dgUserList.DataBind();

I'm trying to figure out how to do all of this at design time in VS
.Net 2002. I'm able to drop in the OleDbConnection object on the Web
Form and point it at the .mdb file. Then I'm able to create an
OleDbDataAdapter and when it asks me what data connection to use, I
specify the OleDbConnection representing the .mdb file and specify an
SQL query to get the data out of the table I want, and at the end, if
I press "preview data" it shows a table representing the data
correctly.

Also at design time, I can drop in a DataView called dvUserList and
then select the DataGrid and set the DataSource property to
dvUserList. I can also drop in a DataSet (called dsUnamesStuff) and
create a table in it called Table1, and then by selecting properties
of the DataView called dvUserList I can hit the "Table" dropdown and
it will show dsUnamesStuff->Table1 as a table that I can select.

The missing link is that I can't figure out how to bridge the gap
between the DataSet that is linked to my DataGrid, and the
OleDbDataAdapter that provides access to the data I want. I've taken
every line in the run-time code above, and found the design-time
equivalent, except for this one line:

objAdapter.Fill(objDataSet, "zquser");

Where in the design view of the adapter can I connect it to a table in
the dsUnamesStuff DataSet? If I select the dsUnamesStuff DataSet and
browse the "Tables" Collection properties, it lets me add and remove
new tables but it doesn't let me create any that are populated by the
OleDbDataAdapter. Or if I select the OleDbDataAdapter, I can't see
any editable properties that can connect it to the DataSet.

If anyone has time, I'm also confused about the "TableMappings" on the
OleDbDataAdapter. If I select the OleDbDataAdapter and click on the
button to edit its "TableMappings" properties, the dialog box that
opens says, "For each column in the source table, specify the name of
the corresponding column in the dataset table". What I don't
understand is what this sentence means by "the dataset". Since there
can be more than one DataSet declared in the code, and any of them can
be passed as an argument to the OleDbDataAdapter.Fill() method, what
does "the dataset" refer to at design time? Or does that just mean
that those column mappings will be applied whenever *any* DataSet is
passed at run time to the Fill() method.

Thanks very much for any help you have time to give me!

-Bennett
 
B

Bennett Haselton

Cor Ligthert said:
Bennett,

A quiet long message.

Yes -- thanks for reading it through and helping me :)

I tried what you suggested -- instead of dragging and dropping a new
DataSet in from the Toolbox, I right-clicked the OleDbDataAdapter and
picked "Generate DataSet". This created a class called
DatabaseAuthInVS.dsUnamesStuff which is derived from DataSet, and
created an instance of it called dsUnamesStuff1, such that I was now
able to go to properties for dvUserList and in the "Table" dropdown I
was able to select dsUnamesStuff1->wbuser.

However it's still slightly inelegant because I have to add these
lines to the Page_Load method to make it work:

oledbdaUnamesFromUsers.Fill(dsUnamesStuff1, "wbuser");
dgUserList2.DataBind();

If leave out the
dgUserList2.DataBind();
line, then the DataGrid doesn't render at all. If I leave out the
oledbdaUnamesFromUsers.Fill(dsUnamesStuff1, "wbuser");
line, then the DataGrid renders with the column headers, but with no
rows to represent the actual data.

I'm not too lazy to add those lines every time :) but I'm wondering
because this looks like a sign that I might be doing something wrong.
Is there a reason the IDE doesn't add the lines of code automatically
to fill the DataGrid control with the data from the data source it's
bound to?
I do not know anymore how it exactly was in VB2002
because the OleDb part is changed in VB2003 so I tell it for VB2003 for what
I readed in your message it is maybe still the same.

You can select a Oledbdataadapter from your toolbox to your form. Than
starts a wizard that lets you tell the connection and the selectstring.
(This is the part I am in doubt if it was already in VB2002).

Than you can do a right click on that adapter that than is apeared bellow on
your form and generate the dataset.

You drag a dataview on your form; in the properties of that can be set the
databinding to the table you want to bind, watch for it that you set it to
the table and not to the dataset that is an often made error.

Than you can drag a datagrid on your form in which properties you can set
the databinding to the dataview.

I hope that what I have told about the table does answer as well your other
question about the dataset table. With the design method you are inclined to
make always datasets (although it is better that you use one, that can as
well using the designer). This means that you have to use the properiete
table from that dataset when you are doing things using the designer.

I hope this helps?

Cor

I know how to hook up an OleDbConnection, an OleDbDataAdapter, a
DataSet, and a DataView to a DataGrid named dgUserList at run time:

string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\shared\\test-database.mdb";
string strSQL = "SELECT username as uname, password as pword FROM
wbuser;";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL,
objConnection);
objAdapter.Fill(objDataSet, "zquser");
DataView objDataView = new DataView(objDataSet.Tables["zquser"]);
dgUserList.DataSource=objDataView;
dgUserList.DataBind();

I'm trying to figure out how to do all of this at design time in VS
.Net 2002. I'm able to drop in the OleDbConnection object on the Web
Form and point it at the .mdb file. Then I'm able to create an
OleDbDataAdapter and when it asks me what data connection to use, I
specify the OleDbConnection representing the .mdb file and specify an
SQL query to get the data out of the table I want, and at the end, if
I press "preview data" it shows a table representing the data
correctly.

Also at design time, I can drop in a DataView called dvUserList and
then select the DataGrid and set the DataSource property to
dvUserList. I can also drop in a DataSet (called dsUnamesStuff) and
create a table in it called Table1, and then by selecting properties
of the DataView called dvUserList I can hit the "Table" dropdown and
it will show dsUnamesStuff->Table1 as a table that I can select.

The missing link is that I can't figure out how to bridge the gap
between the DataSet that is linked to my DataGrid, and the
OleDbDataAdapter that provides access to the data I want. I've taken
every line in the run-time code above, and found the design-time
equivalent, except for this one line:

objAdapter.Fill(objDataSet, "zquser");

Where in the design view of the adapter can I connect it to a table in
the dsUnamesStuff DataSet? If I select the dsUnamesStuff DataSet and
browse the "Tables" Collection properties, it lets me add and remove
new tables but it doesn't let me create any that are populated by the
OleDbDataAdapter. Or if I select the OleDbDataAdapter, I can't see
any editable properties that can connect it to the DataSet.

If anyone has time, I'm also confused about the "TableMappings" on the
OleDbDataAdapter. If I select the OleDbDataAdapter and click on the
button to edit its "TableMappings" properties, the dialog box that
opens says, "For each column in the source table, specify the name of
the corresponding column in the dataset table". What I don't
understand is what this sentence means by "the dataset". Since there
can be more than one DataSet declared in the code, and any of them can
be passed as an argument to the OleDbDataAdapter.Fill() method, what
does "the dataset" refer to at design time? Or does that just mean
that those column mappings will be applied whenever *any* DataSet is
passed at run time to the Fill() method.

Thanks very much for any help you have time to give me!

-Bennett
 
C

Cor Ligthert

Hi Bennett,

I even had not the idea you where using a webpage datagrid.
(I could had seen it from that databind, it was however not that deep I did
read it)

:)

You have always to fill the dataset in code, you cannot pass that.

(Do not forget to set If not IsPostBack, and probably it can be easy to save
your dataset in a session, however those things the designer does not do for
you)

I hope this helps anyway?

Cor
Bennett,

A quiet long message.

Yes -- thanks for reading it through and helping me :)

I tried what you suggested -- instead of dragging and dropping a new
DataSet in from the Toolbox, I right-clicked the OleDbDataAdapter and
picked "Generate DataSet". This created a class called
DatabaseAuthInVS.dsUnamesStuff which is derived from DataSet, and
created an instance of it called dsUnamesStuff1, such that I was now
able to go to properties for dvUserList and in the "Table" dropdown I
was able to select dsUnamesStuff1->wbuser.

However it's still slightly inelegant because I have to add these
lines to the Page_Load method to make it work:

oledbdaUnamesFromUsers.Fill(dsUnamesStuff1, "wbuser");
dgUserList2.DataBind();

If leave out the
dgUserList2.DataBind();
line, then the DataGrid doesn't render at all. If I leave out the
oledbdaUnamesFromUsers.Fill(dsUnamesStuff1, "wbuser");
line, then the DataGrid renders with the column headers, but with no
rows to represent the actual data.

I'm not too lazy to add those lines every time :) but I'm wondering
because this looks like a sign that I might be doing something wrong.
Is there a reason the IDE doesn't add the lines of code automatically
to fill the DataGrid control with the data from the data source it's
bound to?
I do not know anymore how it exactly was in VB2002
because the OleDb part is changed in VB2003 so I tell it for VB2003 for what
I readed in your message it is maybe still the same.

You can select a Oledbdataadapter from your toolbox to your form. Than
starts a wizard that lets you tell the connection and the selectstring.
(This is the part I am in doubt if it was already in VB2002).

Than you can do a right click on that adapter that than is apeared bellow on
your form and generate the dataset.

You drag a dataview on your form; in the properties of that can be set the
databinding to the table you want to bind, watch for it that you set it to
the table and not to the dataset that is an often made error.

Than you can drag a datagrid on your form in which properties you can set
the databinding to the dataview.

I hope that what I have told about the table does answer as well your other
question about the dataset table. With the design method you are inclined to
make always datasets (although it is better that you use one, that can as
well using the designer). This means that you have to use the properiete
table from that dataset when you are doing things using the designer.

I hope this helps?

Cor

I know how to hook up an OleDbConnection, an OleDbDataAdapter, a
DataSet, and a DataView to a DataGrid named dgUserList at run time:

string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\shared\\test-database.mdb";
string strSQL = "SELECT username as uname, password as pword FROM
wbuser;";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL,
objConnection);
objAdapter.Fill(objDataSet, "zquser");
DataView objDataView = new DataView(objDataSet.Tables["zquser"]);
dgUserList.DataSource=objDataView;
dgUserList.DataBind();

I'm trying to figure out how to do all of this at design time in VS
.Net 2002. I'm able to drop in the OleDbConnection object on the Web
Form and point it at the .mdb file. Then I'm able to create an
OleDbDataAdapter and when it asks me what data connection to use, I
specify the OleDbConnection representing the .mdb file and specify an
SQL query to get the data out of the table I want, and at the end, if
I press "preview data" it shows a table representing the data
correctly.

Also at design time, I can drop in a DataView called dvUserList and
then select the DataGrid and set the DataSource property to
dvUserList. I can also drop in a DataSet (called dsUnamesStuff) and
create a table in it called Table1, and then by selecting properties
of the DataView called dvUserList I can hit the "Table" dropdown and
it will show dsUnamesStuff->Table1 as a table that I can select.

The missing link is that I can't figure out how to bridge the gap
between the DataSet that is linked to my DataGrid, and the
OleDbDataAdapter that provides access to the data I want. I've taken
every line in the run-time code above, and found the design-time
equivalent, except for this one line:

objAdapter.Fill(objDataSet, "zquser");

Where in the design view of the adapter can I connect it to a table in
the dsUnamesStuff DataSet? If I select the dsUnamesStuff DataSet and
browse the "Tables" Collection properties, it lets me add and remove
new tables but it doesn't let me create any that are populated by the
OleDbDataAdapter. Or if I select the OleDbDataAdapter, I can't see
any editable properties that can connect it to the DataSet.

If anyone has time, I'm also confused about the "TableMappings" on the
OleDbDataAdapter. If I select the OleDbDataAdapter and click on the
button to edit its "TableMappings" properties, the dialog box that
opens says, "For each column in the source table, specify the name of
the corresponding column in the dataset table". What I don't
understand is what this sentence means by "the dataset". Since there
can be more than one DataSet declared in the code, and any of them can
be passed as an argument to the OleDbDataAdapter.Fill() method, what
does "the dataset" refer to at design time? Or does that just mean
that those column mappings will be applied whenever *any* DataSet is
passed at run time to the Fill() method.

Thanks very much for any help you have time to give me!

-Bennett
 

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