problem with refreshing the datagrid (vb.net 2003)

x86

Member
Joined
Jan 22, 2006
Messages
10
Programming Experience
Beginner
Hello, I'm trying to refresh the datagrid after using the SQL UPDATE statement. The data changes physically in the database but the datagrid is not affected. The data is changed only after i restart the program.

How can i get the datagrid to refresh or update?

I have tried using, among other code, the refresh() method, but it does not work.

The way i understand from reading some sites is that the data from the datagrid is suppose to be cleared and then it can be refreshed.

This is the code i placed inside a button:

daDataAdapter.Update(DsDataSet.Tables("tblMyTable"))
DsDataSet.AcceptChanges()
DsDataSet.Tables("tblMyTable").Clear()
daDataAdapter.Fill(DsDataSet, "tblMyTable") 'IGNORES THIS LINE I GUESS
dgDataGrid.Refresh()

This code only clears the datagrid. Why does it not run the fill() method?
 

big_p

New member
Joined
May 30, 2006
Messages
1
Programming Experience
3-5
I’m using an access database with an odbc connection, hope you can modify this so it works for you. i created a connection with the odbc wizards and it didn't let me update the displayed values. So I created a table in code and loaded the values in it, then bound it to the datagrid.

Public Sub reload()

Dim m_DataSet As DataSet

' Build the DataSet.
m_DataSet = New DataSet("bev")

' Build the bevCode table.
Dim dt_bev As New DataTable("bevCode")
m_DataSet.Tables.Add(dt_bev)
dt_bev.Columns.Add("Bev Name", GetType(String))
dt_bev.Columns.Add("Bev Price", GetType(Double))

Dim reader As System.Data.Odbc.OdbcDataReader
Me.OdbcConnection1.Open()

reader = Me.OdbcSelectCommand1.ExecuteReader

With reader
While .Read

' Populate the bevCode table.
Dim data(1) As Object
data(0) = .GetString(0)
data(1) = .GetDouble(1)
dt_bev.Rows.Add(data)

End While
End With

reader.Close()
OdbcConnection1.Close()


' Bind the DataGrid to the DataSet.
DataGrid1.DataSource = m_DataSet
DataGrid1.DataMember = "bevCode"

Me.DataGridTableStyle2.MappingName = "bevCode"

End Sub
 
Last edited:
Top Bottom