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?:)

Recommended Answers

All 2 Replies

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

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.


' 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.