I am creating one application visual basic and sqlce
I have two forms name Form1 and Form2.
I used Form1 to add data to database using OLeDb command and used Form2 to show data in datagridview by using dataset
I used following code:
FFORM1 CODE is as following
Private Sub Add_data() Try Dim DBConn As OleDbConnection Dim DBInsert As New OleDbCommand DBConn = New OleDbConnection(Myconnection_String) DBInsert.Connection = DBConn DBInsert.Connection.Open() DBInsert.CommandText = "INSERT INTO user(name, designation, age) VALUES (" + textbox1.text + "," + textbox2.text + "," + textbox3.text + ")" DBInsert.ExecuteNonQuery() MsgBox("Data added successfully.", MsgBoxStyle.OkOnly) DBConn.Close() DBConn.Dispose() Catch ex As System.Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error") End Try End Sub
FORM 2 : In visual studio 2008 designer I added a dataset named 'mydataset' and tableadapter 'usertableadapter' and succesfully created Fill query. I added one datagridview to form2 and in design mode bind it to the mydataset and its binding source
ON FORM2 I CODE IS AS FOLLOWING.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.userTableAdapter.Fill(Me.myDataSet.user) Me.DataGridView1.Refresh() End Sub
My Problem is :
Form2 Datagridview show the old data only, it do not show the recently added data by form1. I mean
When I build my application datagridview show the data which is already in the database, but it does not show the data which is added by the form1 during run time.
Some one suggested me to fill the datagridview at run time by using OLeDB command.
Then I created Form3 to fill the datagridview2 by using OLedb command and datareader and found that Form3 shows the recently(added by Form1 at run time) added data.
Use of Designer dataset is required for me , because I am using the similar dataset to create report.
How my Form2 dataset,datagridview can show the latest data from the database