Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VS2008 - Data Designer - How to do other db queries 1

Status
Not open for further replies.

csutton

Programmer
Dec 27, 2000
213
US
Ok, I'm completely confused here:

I am using vs.net 2008 and have the forms all set up (grids, data entry forms, etc) using tableadapters i designed in the IDE using the data designer.

However, sometimes I just want to get basic information from the database using a SELECT statement, or maybe an UPDATE command. Another instance would be verifying username/passwords in a database table from a login form.

Do I then I have to do these queries the old fashioned way via code or is there somehow I can design the queries in the data designer and access it via code?

Thanks,
Chris


Chris Sutton
 
You can do it either way. I prefer coding myself especially if it is as simple as querying a username/password, but you don't have to just build a second one. If it is in a different database then you have to start with a second connection with a new DataSet and BindingSource. If it is the same database then you can just make a new TableAdapter in the same DataSet.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Ok... How do I access table adapters and queries in my dataset. Example. Datatable named client and table adapter named fillbyclientid (or if I want to get just a single value--both are possible).

Thanks!
If you could give example code that would be awesome.

Chris Sutton
 
Let me ask this first how did you setup your dataset and especially the table adapters in the first place then? Maybe I'm confused on what you are wanting to know. Are you asking how do you make them or how do you get the data from them in code?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I have them designed in the data designer in the IDE. So far, I've. Only needed to use grids and data entry controls to interact with the dataset/tableadapters. But I have a zip code field I'd like to be able to do a city/state lookup in the db and things like verify username/password and I'm sure there will be more.

Thank you!!

Chris Sutton
 
So if you are using the existing table you think of it like this when you look at the data designer IDE you are looking at the DataSet. It is a container. Each object you see is generally going to be a DataTable with a TableAdapter. You will see the DataTable on the top with the fields it contains and should see the TableAdapter used to fill it. The the easiest way for you is going to be in the data designer IDE right click->Add->TableAdapter and follow the wizard to make your second one. The DataTable by default if it is a single table then the DataTable is named after the table. If it uses multiple tables then they use DataTable1 (2,3,4,etc) and then the DataAdapter is generally named DataTable1TableAdapter.

If you need the table from a totally separate database you start one step up and use server explorer to create the connection and follow the wizard.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Thank you again, I got all that. I have several TA's designed, but I do not know how to use them from *code*.

Example (just 1 instance of several):

I have a username/password box. The user fills them in and clicks LOGIN. I want to, via code, verify the USERNAME/PASSWORD via the TA.

Or.... even though I'm using the data designer for the forms, do I need to start over with a sqlconnection and sqldatareader, etc. if I'm using code?

Thank you!!

~~ Chris ~~
 
It really all depends how you have everything set up (DataSet/DataTable/TableAdapter/etc) and how you are querying all the data. If you have all of that then one way to get the information could be:

Code:
Me.DataSet1.DataTable1.Rows(1).Item(0)
or
Code:
Dim dtCurrent As DataTable = Me.DataSet1.DataTable1
dtCurrent.Row(1).Item(0)
or or or or . It really just all depends.

Maybe check here: Find at what point in all of the steps you are at and then move forward from there. If you have some code that is almost working or something then post that. I'm just not getting at what point your problem starts and there are whole books on just the general subject of getting data in Visual Studio/VB.Net.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen,

I'm not really sure how to explain this but I'm going to try.

Currently, I have NO database connections coded by hand. I designed all of the dataset in the IDE via the Data Designer. I have forms with GRIDS and point & clicked the connection to the data. I have forms with textboxes that display client name, address, etc. and all of that is connected to the dataset via the IDE (using the properties).

I'm do the point now that I need to access data via CODE. In 1 example, I have a login form with 2 fields: username and password.

When the user clicks LOGIN, I need a way of verifying that the username & password match whats in the database. There is no way to do this via the IDE by point & click.

Again, another example would be on my client demographic form, there is a CITY/STATE field and ZIP CODE. I need to query the DB to get the CITY/STATE combination based on the entered ZIP CODE. I don't know how to use the TABLEADAPTER (not datatable) in code since I cannot point/click a query that way.

So, my big question is do I have to create my own db connection, query, etc. or can I somehow use the TABLEADAPTER that I created in the data designer by CODE?

Is it a little more clear ?

Thanks,
Chris


~~ Chris ~~
 
I finally figured out how to do this! lol I found a little hole in the wall that gave CODE examples instead of drag&drop / point & click examples of using Typed Datasets.

Anyone else who may be confused, please visit:



Thank you for your help Sorwen.


~~ Chris ~~
 
np. I'm glad you were able to find something that helped.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top