DataAccessApplicationBlock without stored procedures?

G

Guest

Hi;

Are there examples somewhere of how to do an insert, update, select, &
delete without any stored procedures?
 
G

Guest

Hello;

I don't think this is waht I want. I need to be able to create a row, select
a single row, update a single row, and delete a row. And in each case pass
parameters to the command.

Once I have a DataAdapter with the data I can update, but the problem
remains doing the select to populate the DataAdapter.

Or am I missing something?
 
W

W.G. Ryan - MVP

David:

Comments Inline:
David Thielen said:
Hello;

I don't think this is waht I want. I need to be able to create a row
DataRow Dro = DataTableName.NewRow();

or DataRow Dro = DataSetName.Tables[TablenamorIndex].NewRow();

Then, after you set the values, Make sure you add it to the Datatable...

DataTableName.Rows.Add(Dro);

To Select a Row, Look at the articles I have here (Efficiently Using ADO.NET
x.x )
http://www.google.com/search?q=efficiently+using+&domains=KnowDotNet.com&sitesearch=KnowDotNet.com

To Update a Single row..

DataAdapter.Update(Dro);
or DataAdapterName.Update(DataTableName.Rows[RowIndex]);

To Delete a Single Row:

Mydatatable.Rows[RowIndex].Delete();
MyDataAdapter.Update(Mydatatable.Rows[RowIndex]);

To map a parameter value to a given column..
DataTable MydataTable = new DataTable("MyTable");

DataColumn MyColumn = new DataColumn("MyColumn", typeof(Int32));

MydataTable.Columns.Add(MyColumn);

SqlCommand cmd = new SqlCommand();

cmd.Parameters.Add("@ParamName", SqlDbType.Int, 4, "MyColumn"); //This will
now map to the value

//of MyColumn. If I have a dataAdapter, as it goes through the rows and
figures

//out what commands to call (Update, Insert, Delete), if will take the value
of MyColumn

//And set it to whatever the current row's MyColumn value is. Do this for
each parameter.

---------The best way to see how this all works though is to create a
Winforms app and use the Data Adapter Configuration Wizard. Just run through
it and select Sql Statement instead of Stored Procs. (Make sure the table
you pick has a key so all of the commands can be generated and use a Single
Table). Then, look at the code. For each value in the Select statement,
you'll see a parameter added with a column name mapped to it. When you fill
a dataTable, it will fill the table with the query naming each column the
same as the name in the query, or it'll use ColumnMappings (which let you
map a different named column in the DB to a different named column in your
datatable).

You can also add or remove parameters if you don't want them updated. Just
take them out of the commandText and then take out the params.

Run through this and it'll give you a good idea how it works. I'll gladly
walk you through anything else.
, select
 
G

Guest

Hi;

It turns out thaa DAAB is Sql Server & Oracle only and we at a minimum must
support MySql and DB2 also. So we can't use DAAB. Thank you for the help.
 
C

Cor Ligthert [MVP]

David,

Sorry I misreaded your question. (I probably only have looked at the test
not the subject)

Cor
 
G

Guest

Or I wasn't real clear. I think I tend to not put enough background in my
posts. Anyways, thank you for the help.
 
W

W.G. Ryan - MVP

David:

I think I may have mentioned it in another post, but you have the code for
the DAAB or any of the other blocks. Many times it's necessary to augment
them or customize them, for instance, to address encrypted connection
strings. the code however is pretty similar for both of those two
roviders - well, it depends on which library you use to access them but
it's still fairly close. It may be worth it to extend them using the same
methodology, that'll ultimately give you support for 4 different dbs. I
think I remember a friend of mine doing this for the DB2 provider, I shot
him an email and will get back to you if he has anything.
 
G

Guest

Hi;

How does the DataAdapter work with the DataAccessApplicationBlock? I thought
if I use DataAccessApplicationBlock it can give me a DataSet but I have to
hit the database through DataAccessApplicationBlock?
 
L

Luke Zhang [MSFT]

As I said in another post, currently DataAccessApplicationBlock didn't work
with DB2 and mysql. So my suggestion is to use ADO.NET (dataadapter)
directly.

Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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