Link to home
Start Free TrialLog in
Avatar of deanlee17
deanlee17

asked on

vb.net refresh dataset

Hi Experts,

I have the following code to setup to load a datagrid with data from a table in a dataset. In a seperate procedure I need to refresh the data in the table in the dataset (the table in the back end database will have been modified by this time). I just cant figure out how to do it?...

Thanks,
Dean...

Public Sub LoadLinesGrid()

Dim LinesConnString As String
Dim LinesConnConect As SqlConnection
Dim LinesConnAdapter As New SqlDataAdapter
Dim LinesSelectSql As String
Dim LinesSQDataset As New DataSet()
Dim MyIndex As Integer

LinesConnString = "Data Source=XXXXX"
LinesConnConect = New SqlConnection(LinesConnString)

         
LinesSelectSql = "Select * FROM WPFtblSmartQuoteLines where LinesAstuteRef = '" & FlxHeader(MyIndex, 8).Text.ToString & "'"
           

Try
'Open connect to OMSytem
    LinesConnConect.Open()
'Insert SQL Select COMMMAND above
    LinesConnAdapter.SelectCommand = New SqlCommand(LinesSelectSql, LinesConnConect)
'Run SQL Select Query
    LinesConnAdapter.SelectCommand.ExecuteNonQuery()

'Load Dataset with results..
    LinesConnAdapter.Fill(LinesSQDataset)

'Set Dateset to load into DbGrdGRNInfo
    FlxLine.ItemsSource = LinesSQDataset.Tables(0).DefaultView

'Clear SqlAdaptor
    LinesConnAdapter.Dispose()
    LinesSelectSql = Nothing
'Close Connection to OMSystem
    LinesConnConect.Close()


Catch ex As Exception
    MsgBox(ex.ToString)
End Try

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deanlee17
deanlee17

ASKER

Because of the way other code is linking in I cannot just re-run LoadLinesGrid. Can I force the dataset to refresh itself, found the code below but no idea how to change it to my needs....

        Dim UpdateAD As New OMSystemDataSetTableAdapters.tblGIQTableAdapter
        UpdateAD.Update(OMSDataSource.tblGIQ)


Thanks
Refreshing is reloading so either your call that method or you write duplicate code to reload that dataset. How is other code linking there?
Ah ur right, its fine, thanks.