469,909 Members | 1,738 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

DataAdapter combining data in DataGridView Question

Hello All,

I'm stumped with this one. I have a Database table ("PROD") and I have set up 2 different opens for it. As you can see I alias two of the columns in
the first open.

I run OpenST(), load a combo box for date selection. I then close the connection, and remove the dt from the dataset. Now I run OpenST1() and I want
to get all the columns for those dates and items selected.

In my testing I put a datagridview on the form and assigned dtST as the datasource. What I got in the dgv to my surprise was: STdate, STItem, (the
aliased columns from the 1st open) AND all the columns from the second select.

The dgv combined the data from the 1st open (15 rows) and then 125 rows of data from the 2nd open. After the first open I tried various combinations
of:

cnST.Close()
cnST.Dispose()
ds.Tables.Remove(dtST)
daST.Dispose()
dtST.Dispose()
cmbST.Dispose() 'Command Builder

Why do I have data from both data adapters in my dgv?

Please shed some light on this.

Thanks,

Hexman

vb.net 2005, Access DB
************************************************** ****
Private Sub OpenST()
cnST = New OleDbConnection(...)

STQrySel = "Select DISTINCT PRDate as STDate, PRItem as STItem " & _
"FROM PROD " & _
"WHERE PRDate = ? " & _
"ORDER BY PRDate, PRItem ; "
STQryAdd = " ; "
STQryDel = " ; "
STQryUpd = " ; "
daST.SelectCommand = New OleDbCommand(STQrySel, cnST)
daST.SelectCommand.Parameters.Add("ProdDate", OleDbType.Date, 8)
daST.SelectCommand.Parameters("ProdDate").Value = SeekProdDate
daST.InsertCommand = New OleDbCommand(STQryAdd, cnST)
daST.DeleteCommand = New OleDbCommand(STQryDel, cnST)
daST.UpdateCommand = New OleDbCommand(STQryUpd, cnST)
STCount = daST.Fill(dtST)
ds.Tables.Add(dtST)
End Sub

Private Sub OpenST1()
cnST = New OleDbConnection(...)

STQrySel = "Select * " & _
"FROM PROD " & _
"WHERE PRDate = ? and PRItem = ? " & _
"ORDER BY PRDate, PRItem, PRProdCode ; "
STQryAdd = " ; "
STQryDel = " ; "
STQryUpd = " ; "
daST.SelectCommand = New OleDbCommand(STQrySel, cnST)
daST.SelectCommand.Parameters.Add("ProdDate", OleDbType.Date, 8)
daST.SelectCommand.Parameters.Add("ProdItem", OleDbType.VarChar, 3)
daST.SelectCommand.Parameters("ProdDate").Value = SeekProdDate
daST.SelectCommand.Parameters("ProdItem").Value = SeekProdItem
daST.InsertCommand = New OleDbCommand(STQryAdd, cnST)
daST.DeleteCommand = New OleDbCommand(STQryDel, cnST)
daST.UpdateCommand = New OleDbCommand(STQryUpd, cnST)
STCount = daST.Fill(dtST)
ds.Tables.Add(dtST)
End Sub
Nov 30 '06 #1
0 2010

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by AKJTR | last post: by
13 posts views Thread by Doug Bell | last post: by
8 posts views Thread by Zorpiedoman | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.