Database-binding issue

djole_bg2004

New member
Joined
Jan 11, 2005
Messages
1
Programming Experience
Beginner
Hi everyone,
I have a problem populating textboxes with data from my database. I have a db w/ 3 tables: customers(customers' info like customerID,fname,lname,address...), movie_due(associative entity made w/ primary key of CustomerID and MovieID and some additional info), and movies(info about movies like movieID,title....). I have an application that allows me to browse through the customers displaying all thei info simply by clicking on buttons like "|<" "<" ">" ">|". I mangaed to do this by creating an instance of SqlDataAdapter and passing it an SQL statement that selects all the fields from Customers table. Now what I'm trying to do is that as I browse through the customers if I run into a customers who has movies rented this would automatically show in three available textboxes (assume a customer can check out max 3 movies at a time). For example, I browse through the customers and I run into a John Smith who has rented 2 movies so the result is that I see all his info plus in 2 textboxes I see movieIds of these two movies. To be able to do this I need a new select statement that would select MovieID from Movie_Due table where CustomerID=CustomerID of the record currently shown. Can anyone help me do this or give me an hint? I tried to put 2 sql statements into SqlDataAdapter but it won't work. In my BindFields Sub I would put:

....
txtPhone.DataBindings.Clear()
txtRentedMovie1.DataBindings.Clear()
txtRentedMovie2.DataBindings.Clear()
txtRentedMovie3.DataBindings.Clear()

....
txtPhone.DataBindings.Add("Text", myDV, "Phone")
txtRentedMovie1.DataBindings.Add("Text", ???, "MovieID")

As you can see myDV is already populated with the info about Customers so I don't know if I should create a new DataView to be able to solve my problem or...?
Thanks in advance, Dj.
 
You can combine the three tables into one table by using INNER JOIN statements in your SQL SELECT statement.
You can create the SQL statement graphically by using the Query Builder in Visual Studio.
If you drag a dataAdapter to a form (for an existing DataAdapter, right-click and select 'Configure Data Adapter...') to start the Data Apadter Configuration Wizard. After selecting the connection and 'Use SQL Statements' radio button, the next screen has a button for the Query Builder.
 
Back
Top