views:

47

answers:

3

I am using Visual Studio 2008 for creating a Winforms app. I have connected a database to it called XStats. There is one table in it called XGames and in that table 2 fields, XIndex (the primary key field) and GameNumber. Using the following code I can add records to the database, the data is taken from a text box, but once added I cannot view them unless I shut down the app and restart it.

con.ConnectionString = connectionString

con.Open()

Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandText = "INSERT INTO XGames (GameNumber) VALUES ('" + TextBox701.Text + "')"
cmd.ExecuteNonQuery()

con.Close()

The existing records in the database are displayed on the form in detailed view via a binding navigator. How can I make it so that I can view all the records in the database, even those that are added during the current session. As will be obvious, this is my first attempt at creating and using a database with a win forms app, so all and any help is most welcome. Thank you.

A: 

There's no simple answer to this question. In short you could poll the db (setting maybe a timer) to see if there are new records.

/There are better options that writing SQL code directly in a string, built on the fly; but this is another story.

vulkanino
A: 

See SqlDependency Class. Requires SQL Server Service Broker

Query Notifications in SQL Server (ADO.NET)

Mitch Wheat
A: 

Do you update the control when u press the button to insert a item? if not this could be a start. (Call the update method of the control u use to display the items in, at the end of the Button_Click event.)

What I usually did a year back, was to keep a seperate list in my code with al items of the database in it, and when an item is inserted to the db, its added to the list as well. Therefore u can check beforehand if an item is already in the database, and reject it before an SQL statement is executed. (yes i know, not the best way to program, but we have to begin somewhere and learn.)

Emerion