Doubt using ADO.NET

  • Thread starter Thread starter Ashwin Murali. T
  • Start date Start date
A

Ashwin Murali. T

I'm developing a supermarket application using VB.NET. I have a situation
where there are two tables namely Categories and SubCategories.

I have a form which has a combo box which lists the Categories present in
the Categories Table. I have a textbox where the user enters the data which
he wants to insert into the SubCategories table with the selected Category
as the foreign key.

The insertion must take place on the condition that no other value of the
same kind exists in the SubCategories table. How do i query for that and
find out from the dataset??? Or else, is there another way around for
this???
 
Hi, you have to do it using a DataRelation...

Greetings...

Miguel Ortiz Falcón
(e-mail address removed)
 
Hi,

There are several ways to query in the datatable,
DataTable.Select(strQuery), or DataView.RowFilter =
strQuery.

Suppose in a dataset, ds, there are two datatables,
Categories and SubCategories. You can query SubCategories
table either

DataRow[] rows = ds.Tables["SubCategories"].Select
(strQuery);

Or

DataView dv = ds.Tables["SubCategories"].DefaultView;
dv.RowFilter = strQuery;

HTH

Elton Wang
(e-mail address removed)
 
I'm developing a supermarket application using VB.NET. I have a situation
where there are two tables namely Categories and SubCategories.

I have a form which has a combo box which lists the Categories present in
the Categories Table. I have a textbox where the user enters the data which
he wants to insert into the SubCategories table with the selected Category
as the foreign key.

The insertion must take place on the condition that no other value of the
same kind exists in the SubCategories table. How do i query for that and
find out from the dataset??? Or else, is there another way around for
this???

You can set the DataColumn's Unique property to true. When you have done that
any attempt to add a value to that column in your DataTable object will raise an
error that you can trap in a try block and handle appropriately.

In the above I am assuming that you are using DataSet objects at the client. if
you are not, then it will be best (in my opinion) to Define the column at the
database as a unique column. When you try to insert a value that already exists
in the column at the database an exception will be raised in your ADO .NET code
that you can trap in a try block and deal with as you would if you were using
DataSets.

The Book "ADO.NET" by Sceppa has very good discussions and examples of just
about anything you want to know about ADO.NET.

Good luck!

Otis Mukinfus
http://www.otismukinfus.com
 
Back
Top