Datagrid not Refreshing

G

Guest

Here's my question..

I can't seem to get my datagrid to refresh. I have a Dataset that automagically populates the datagrid. It's a two parameter SQL statement that I am using. Here's an example of that code..

datasetkey = mydot.OpenDataAdapter("Select MASYS, MAFLD, MADATA, MAEQV from QS36F.MAPDATA WHERE MASYS = ? AND MAFLD = ?"

Dim adapter As System.Data.Odbc.OdbcDataAdapter = mydot.getAdapter(datasetkey
mydot.CreateODBCParameter(adapter.SelectCommand, Odbc.OdbcType.Text, "MASYS", MASYS
mydot.CreateODBCParameter(adapter.SelectCommand, Odbc.OdbcType.Text, "MAFLD", MAFLD

mydot.OpenDataset(datasetkey

dg_MappingInfo.SetDataBinding(mydot.getDataSet(datasetkey), "Table"

ts.MappingName = dg_MappingInfo.DataMembe

This is what the functions in the above code are..

Public Function CreateODBCParameter(ByVal dbcmd As System.Data.Odbc.OdbcCommand, ByVal type As Odbc.OdbcType, ByVal name As String, ByVal value As Object
'returns a new paramete
Dim dbParm As Odbc.OdbcParamete
dbParm = dbcmd.CreateParameter(
dbParm.OdbcType = typ
dbParm.ParameterName = nam
dbParm.Value = valu
dbcmd.Parameters.Add(dbParm
End Functio

Public Function OpenDataSet(ByVal key As Integer) As Intege
Dim RS As New System.Data.DataSe
Tr
Me.getAdapter(key).Fill(RS
recordsets.Add(key, RS
Catch ex As Exception When Connection.State =
'forgot to open a connection
MsgBox("No connection to the database", MsgBoxStyle.Critical, "Error"
Return ke
Catch ex As Exceptio
'general error trappin
MessageBox.Show(ex.Message
End Tr
End Functio

Public Function OpenDataSet(ByVal key As Integer) As Intege
Dim RS As New System.Data.DataSe
Tr
Me.getAdapter(key).Fill(RS
recordsets.Add(key, RS
Catch ex As Exception When Connection.State =
'forgot to open a connection
MsgBox("No connection to the database", MsgBoxStyle.Critical, "Error"
Return ke
Catch ex As Exceptio
'general error trappin
MessageBox.Show(ex.Message
End Tr
End Functio

Public Function getAdapter(ByVal key As Integer) As System.Data.Odbc.OdbcDataAdapte
'returns the requested adapte
If adaptersets.Contains(key) The
Return adaptersets.Item(key
Els
Return Nothin
End I
End Functio

Following that when I change the two parameter variables....is it suppose to automagically update the dataset
If so how does it refresh the info on the datagrid

Here's my refresh code when I change the variables...

mydot.getAdapter(datasetkey).SelectCommand.Parameters.Item("MAFLD").Value = MAFL
mydot.getAdapter(datasetkey).SelectCommand.Parameters.Item("MASYS").Value = MASY

mydot.refreshData(datasetkey
dg_MappingInfo.Refresh(

Any suggestions?
 
C

Cor

Hi Steve,

Did you know that when you post to a newsgroup some names in code are
standard.
This makes it for the one who helps you more readable.
So is a ds or a dataset1 mostly a dataset, a RS always a recordset and a
datasetkey something as the key object from the dataset datatable

That is not with you so helping you is very difficult.

The first thing I would change in your code is
mydot.OpenDataset(datasetkey)

dg_MappingInfo.SetDataBinding(mydot.getDataSet(datasetkey), "Table")
ts.MappingName = dg_MappingInfo.DataMember
The two rows above in
dg_MappingInfo.datasource = datsetkey.tables("Table")

And than try again.

I hope this helps,

Cor
 
G

Guest

I appologize for the confusing code.
I did however figure out what the problem was

When I did the refresh function (which I forgot to include) I was doing a reset instead of a clear
Like so..

'My code that refreshes the changed params...then calls the refresh function
mydot.getAdapter(datasetkey).SelectCommand.Parameters.Item("MAFLD").Value = MAFL
mydot.getAdapter(datasetkey).SelectCommand.Parameters.Item("MASYS").Value = MASY

mydot.refreshData(datasetkey
dg_MappingInfo.Refresh(


Public Function refreshData(ByVal key As Integer
'This used to be getdataset(key).reset(
getDataSet(key).Clear(
Me.getAdapter(key).Fill(getDataSet(key)
End Functio

Not sure if any of the code makes sense cause of how 'non standard' it is. But bottom line is it works now
Thanks anyhow.
 
C

Cor

Hi Steve,

Very good, however as an answer on this sentence.

It makes no sence how standard your code is to let it work, only if you show
it to others and ask advices, than can confusing names give problems.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top