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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview binding

Status
Not open for further replies.

patrickstrijdonck

Programmer
Jan 18, 2009
97
NL
Hello,

Im creating a simple helpdesk program in Visual C# 2008. im a beginner and i find this a good start to learn the C# Programming, but im a bit stuck now!

ive got 2 tables, tblTickets & tblNotes

these tables are related on field Ticketnumber.

now in Visual C# ive got a form with some fields and a navigator (bindingnavigator) to navigate between all tickets.

now ive added a datagridview which must show all notes related to the ticketnumber which is open in the main form. and when i go to the next form, the datagridview must update to show all notes of that ticketnumber.

so far, ive got the datagridview active, but its showing ALL notes in the whole table.

Can someone help me with this?
 
In your data source try adding a WHERE clause and binding a parameter to the ticket number your main form.

i.e. WHERE ticket_number = @ticket_number

In the where clause you will be given a list of controls for possible binding to @ticket_number
 
Hi BDazzler,

Ive added the WHERE condition, but now i need to have the @ticket_number.

Where can i add the parameter for the ticket number on my main form?
 
I am not sure how you designed the form, but normally there are 2 ways to handle a master-detail form. One is to depend on .NET's binding technology. Another is to load the records only when you need them.

The first option is very easy to implement so long as you properly configured the data relationship of your DataTables. You can read a lot of tutorials about this subject just by googling "ADO.NET databinding tutorial".

But the setback is that, for example on your project, for all the Tickets you want to display, you also need to cache all their corresponding notes. This may work for small amounts of data, but becomes pretty heavy as the dataset grows.

The second option is to load the records only when you need them. For this, you may need to rethink how much data to load per session/transaction and/or how you want to display the records. This is where you will need your ADO.NET / SQL skills. For this, read on tutorials how to use the SqlConnection, SqlDataAdapter, and SqlCommand for a start.

hth [wink]
 
Thanks 8=)

I was looking on google, but i didnt really know where i was looking for(didnt know how to describe), the description: ADO.NET Databinding Tutorial will help in my search, ill post when i find out what im going to do.


P.S. Tickets will grow always as users will add a new problem. each Ticket, will have around 4 Notes. (currently using this solution in Acces, im trying to build the program into C# so i dont need the access GUI anymore.)




 
Well i searched some and found a very simple solution, if its a good solution... only time will tell.

i selected the Table Adapater of the Gridview, and added a WHERE condition to the SQL statement

Where Ticketnumber = ?

this will add a Toolstrip with a textbox and a Button.

I made it invisible, binded the ticketnumber textbox on the mainform with the box on the toolstrip and automaticly runned the query and refill of the gridview.


this is working perfectly, the gridview is now only showing the notes of that specific call.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top