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

DataSet Row Population 1

Status
Not open for further replies.

jaycast

Programmer
Nov 28, 2001
42
0
0
US
I'm trying to populate a data set with data from a SQL statement generated from within the code. However, upon running the Fill() method, the BindingContext of the dataset has a count of 1, while the actual row count of the table involved in the DataSet fill has a count of 2. So, I know my records are in the table, but I can't seem to get them to be displayed from within the bindingcontext.

Am I missing something big here?

Thanks
 
1. Is the dataset bound.
2. and to what is it bound textboxes, datagrid?
3. Some code would be handy.

4. Youre probably missing a mouse.


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Here is my procedure so you can see what I'm doing:

Code:
OleDbConnection1.Open()
        Dim strSearch, strSearchInput(4) As String, intCount As Integer
        Dim x As Integer


        If chkTitle.Checked = True Then
            strTitle = "Title = '" & InputBox("Enter Title for Search", "Title Search") & "'"
        End If
        If chkActor.Checked = True Then
            strActor = "ActorName = '" & InputBox("Enter Actor for Serach", "Actor Search") & "'"
        End If

        strSearchInput(0) = strTitle
        strSearchInput(1) = strActor

        strSearch = "SELECT tblDVD_Main.Director, tblDVD_Main.DVDID, tblDVD_Main.Genre, tblDVD_Main.Original, tblDVD_Main.ProductionCo, tblDVD_Main.Rating, tblDVD_Main.ReleaseYear, tblDVD_Main.Synopsis, tblDVD_Main.Title, tblDVD_Detail.ActorName FROM tblDVD_Main INNER JOIN tblDVD_Detail ON tblDVD_Main.DVDID = tblDVD_Detail.DVDID WHERE "

        For x = 0 To strSearchInput.GetUpperBound(0)
            If Len(strSearchInput(x)) > 0 Then
                If Microsoft.VisualBasic.Right(strSearch, 6) = "WHERE " Then
                    strSearch = strSearch & strSearchInput(x)
                Else
                    strSearch = strSearch & " AND " & strSearchInput(x)
                End If
            End If
        Next x

        MessageBox.Show(strSearch)
        OleDbCommand1.CommandText = strSearch

        DsDVDSearch1.Clear()
        OleDbDataAdapter1.SelectCommand.CommandText = strSearch
        OleDbDataAdapter1.Fill(DsDVDSearch1)

        intCount = DsDVDSearch1.Tables("tblDVD_Main").Rows.Count
        MessageBox.Show(Me.BindingContext(DsDVDSearch1).Count())
        MessageBox.Show(intCount.ToString)
        OleDbConnection1.Close()
Now, let me see if I can answer your questions.

1) I don't believe the DataSet is bound. I'm still trying to understand what you mean by bound. I generated the DS off of a data adapter, then am populating it by the DA Select Statement generated by the code.

2)Textboxes are bound to the dataset. I would have preferred to not bind the textboxes at all since there seems to be less flexability with data binding, but I don't know how and this seemed to be the easiest way to load the data.

3) Code has been provided.

4) Missing a mouse? I don't understand.

Thanks for the reply. I hope this additional information helps you help me:)

 
I think there isnt much wrong with your code allthough you should use the .net way instead of the vb6 way
for example

Code:
Len(strSearchInput(x)) = strSearchInput.length
Microsoft.VisualBasic.Right(strSearch, 6)= strSearch.substring(strsearch.length-7,6)

and the reason why bindingcontext and the row counts are different is because the count you did on bindingcontext doesn't count the number of rows just the number of tables that are bound. So its normal they aren't the same.

and instead of using an array try looking up the arraylist it's more flexible.

you see, youre problem isn't bigger than a mouse.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
While I'm trying to wrap my mind around your suggestions (I'm still trying to get used to the .net way of doing things), I still can't seem to get to the rest of my records after the fill() method.

I have the following that should navigate my recordset forward:

Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.BindingContext(DsDVDSearch1).Position += 1
    End Sub

However, it does absolutely nothing. Is this also a mouse? ;-)
 
and BTW instead

OleDbCommand1.CommandText = strSearch
DsDVDSearch1.Clear()
OleDbDataAdapter1.SelectCommand.CommandText = strSearch

should be this

Code:
OleDbCommand1.CommandText = strSearch
DsDVDSearch1.Clear()
OleDbDataAdapter1.SelectCommand = oledbcommand

or this

Code:
DsDVDSearch1.Clear()
OleDbDataAdapter1.SelectCommand.CommandText = strSearch

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Never mind my last post. I found the problem as I had:

Code:
Me.BindingContext(DsDVDSearch1).Position += 1

Instead of:

Code:
Me.BindingContext(DsDVDSearch1, "tblDVD_Main").Position += 1

Thanks for your help! Here's your star.

And if I'm ever in Belgium, I owe you a beer ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top