ELI.M.

Hi all

I'm planning to write a 2 part project (already started writing the code with VB EXPRESS). the first is the master (admin) program window (form) and the second is the client's only view window (form)

the "admin" insert / edit / update / delete some data on SQLEXPRESS database on a remote pc. the "client" should receive the updates automatically and showed on the screen,

(in a Datagridview and/or textbox's)

I managed to connect to the server and do some editing to the tables and data and the client side can receive and sow the data, BUT, it can't refresh the view of data, it can't receive the latest updated data from the server. unless i exit the client program and running it again.

how can i do automatic refresh/re-reading data



Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

bola shokry

Hi
well ,
I have an opionion
When the Admin make any changes to the database , the server program will send to the connected clients tell them that there are changes in the database (the message may have also the tables names that accepted changes) , when the client get this message it will reload the tables that accepted the changes ..........

good luck in your application




Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

ELI.M.

bola shokry wrote:
Hi
well ,
I have an opionion
When the Admin make any changes to the database , the server program will send to the connected clients tell them that there are changes in the database (the message may have also the tables names that accepted changes) , when the client get this message it will reload the tables that accepted the changes ..........

good luck in your application

The client side is a stand alone pc, with no user. My project is somthing like the billboards in airports that

shows the landing and departures time/date of flights.

the admin side of my project update's data (by connecting to a remote server with sql server express intalled on it) and the billboard (client side that is connect's to sql server express) sould check for updates in intervals time.

so my problem is that the update does take plase. only when i exit and running again the client side program, it updates the screen (datagridview).

so, how do i do this update in code (vb express)

I have already tried this DataGridView1.update(), it did not update anithing.





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

folen

if i get u rigth

to update the data just read it again

just do the same thing u did when u started the client





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

ELI.M.

folen wrote:

if i get u rigth

to update the data just read it again

just do the same thing u did when u started the client

i did, but then i get doubled the datagrid view. it fills the datagrid view twice. so i cleard the datagridview and filld it again but it does not shows the updates.

i think when i'm editing the data it does not send/update the tables on the server with the new data.

so how to update or commit the changes on the server and then re-read it again

what code sould i write (sqldataadapter..... )

but then again, when i'm openning the 'sql server managment tool' and connects to the DataBase, i can see the tables filled with a new data.




Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

bola shokry

The client program hasn't a user that isn't a problem...!

If you cleard the DataGridView an reloaded it again from the database , why that doesn't work , it should ,as long as you say the database is updated successfully. !!!!




Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

ELI.M.

this is the code i wrote for filling the datagridview

Dim ConnectingString As String = "Server=10.0.0.3\SQLEXPRESS,1234;DAtabase=AddressBook;Uid=user1;Pwd=1234" ';Trusted_Connection=YES"

Dim myConnection As New SqlConnection(ConnectingString)

Dim Command As New SqlCommand("SELECT * FROM Contacts", myConnection)

Dim mySqlDataAdapter As New SqlDataAdapter(Command)

Dim myDataSet As New DataSet

Dim myDataTable As New DataTable("Contacts")

myConnection .open()

'fill data grid

myDataTable.Clear()

dgContacts.Update()

mySqlDataAdapter.Fill(myDataTable)

dgContacts.DataSource = myDataTable

myConnection .close()

the initializing vars are set before the above code, oppening a connection, filling the grid and closing connection

what is wrong with it





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

bola shokry

Hi again ELI.M. ,

I see your code is ok , but you should call this code each time the client wants to update its DataGridView (not only the first time ) ..

Did you do that





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

ELI.M.

yes i did.

i even created a button for that 'SubRutine' to run at will.





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

folen

i have been doing vb.net for a while so i forgot some c# but don't u need to databind the datagrid

try:

dgContacts.SetDataBinding(myDataTable, "Contacts")

insted of

dgContacts.DataSource = myDataTable





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

ELI.M.

folen wrote:

i have been doing vb.net for a while so i forgot some c# but don't u need to databind the datagrid

try:

dgContacts.SetDataBinding(myDataTable, "Contacts")

insted of

dgContacts.DataSource = myDataTable

i tried that but the VB Express underline that line of code with a BLUE line.

i looked for the 'SetDataBinding' in the intellisence and could not find it but i found

something similler 'DataBindings' but no go, it marked with a blue underline.

(i use .NET FrameWork v2.0)

i looked into the MSDN, so i allso added on the top of the class this line code:

Imports System.Windows.Forms.DataGridView

but i saw in the MSDN this line insted: Imports System.Windows.Forms.DataGrid





Re: Windows Forms Data Controls and Databinding How do i refresh the DataGridView/TextBox's to show a new data from SQLEXPRESS server ?

Zhi-Xin Ye - MSFT

You can use a timer to update the DataSource for the DataGridView every certain time. something like this

Code Block

Imports System.Data.SqlClient

Public Class Form6

Private Sub Form15_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

Me.updateDataGridView()

Dim timer As New Timer()

timer.Interval = 5000

'5 seconds

AddHandler timer.Tick, AddressOf timer_Tick

timer.Start()

End Sub

Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)

Me.updateDataGridView()

End Sub

Private Sub updateDataGridView()

Dim connstr As String = "Persist Security Info=False;Integrated Security=SSPI;" + _

"Initial Catalog=Northwind;server=localhost"

Dim conn As New SqlConnection(connstr)

Dim sql As String = "SELECT CompanyName,Address From Customers"

Dim da As New SqlDataAdapter(sql, conn)

Dim dt As New DataTable()

da.Fill(dt)

Me.DataGridView1.DataSource = Nothing

Me.DataGridView1.DataSource = dt

End Sub