Help with datagrid

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2007
Posts: 24
Reputation: Alphard is an unknown quantity at this point 
Solved Threads: 0
Alphard Alphard is offline Offline
Newbie Poster

Help with datagrid

 
0
  #1
Sep 13th, 2009
Hi everyone!

I am having difficulties in terms of manipulating data using datagrid. So my problem is this, I have 2 forms;namely, a form for logging in, then secondly, a form which is similar to an inbox. I have a datagrid in my inbox to call on records in my database. The datagrid shows all records, but what I want is to limit data per login of the user. So for example, if I login as "Username" the datagrid will show all the transactions done only by this specific "Username".

What I've tried:
1.) I've tried to pass one variable from my Login Form to my Homepage form then set a place to which I can call the data, namely the Username, afterwhich I've added to it to my sql statement and tried to call on the data, but it doesn't seem to work.

Can anyone give me an idea?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: eliot is an unknown quantity at this point 
Solved Threads: 0
eliot eliot is offline Offline
Newbie Poster
 
0
  #2
Oct 11th, 2009
Hi alphard;
in my opinion what you should do id have two tables in your database one is "username" second is transaction.
Get the relation done between the 2 tables so that username is the primary key flield which is related to username in transaction table,many to one relationship.
Now starting from vb.net editor code, you should add a tool
oledbconnection and 2 dataadapters because you have 2 tables. The wizard will open for the sql statement one for each dataadapter, set the tables by selecting then, through sqlqueries.
Then generate a dataset that englobes the 2 tables.
After that click twice on the .xsd file and sort the schema by
adding a new relation ship ((username via transaction id)).
Use the fill method to fill the data set.
Write the necessary statements to save back to the database:

Like getchanges and update dataadapter and accept changes.

Youare set up.

Make a button to trigger the code like name it get data.
You will see that in the datagrid shows the username and besides it there is a plus sign, click it and you would have the transactions for that username.

Good luck
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 292
Reputation: TomW is on a distinguished road 
Solved Threads: 38
TomW TomW is offline Offline
Posting Whiz in Training
 
0
  #3
Oct 11th, 2009
I would have to disagree with the majority of the above reply. You should not be retrieving un-needed data from a database and holding it in memory. Write your query to get only the records that you need for this single user.

Originally Posted by eliot View Post

' You do not need to retrieve and store all users in your db.
' Likewise you don't need to retrieve all mail records.
' You have the login username, you only need a
' single table to query the records belonging to this user.

in my opinion what you should do id have two tables in your database one is "username" second is transaction.

Get the relation done between the 2 tables so that username is the primary key flield which is related to username in transaction table,many to one relationship.

' Again this is un-needed but just wanted to point out that
' you do not need seperate DataAdapters for every DataTable in
' a DataSet.
' Also I would suggest writing all your queries as stored procedures
' in whatever database you are using. It is more efficient, flexible
' and provides reusability for other datasets having the
' same queries within your app or other apps using the same db.

Now starting from vb.net editor code, you should add a tool
oledbconnection and 2 dataadapters because you have 2 tables. The wizard will open for the sql statement one for each dataadapter, set the tables by selecting then, through sqlqueries.
Then generate a dataset that englobes the 2 tables.

After that click twice on the .xsd file and sort the schema by
adding a new relation ship ((username via transaction id)).
Use the fill method to fill the data set.

Write the necessary statements to save back to the database:

' Explicitly calling a Dataset/DataTable's AcceptChanges method
' seems to be a very common mistake by many programmers.
' In truth this is rarely needed. Your DataAdapter will automatically
' adjust the row state changes after any action command has
' been executed.


Like getchanges and update dataadapter and accept changes.

Youare set up.

Make a button to trigger the code like name it get data.

' You can not show multiple tables in a single
' DataGridView control in .Net.


You will see that in the datagrid shows the username and besides it there is a plus sign, click it and you would have the transactions for that username.
Last edited by TomW; Oct 11th, 2009 at 6:45 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
access, datagrid, vb.net

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC