Results 1 to 5 of 5

Thread: Data Refresh

  1. #1

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Question Data Refresh

    HI...

    what is the event which refresh data instead of load event !
    I mean the data will be refresh every time when the form event change from hide to show !?

    Any idea please...

    Regrads...

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Data Refresh

    You haven't given enough (in fact, any) detail yet for us to be able to help.. please read the sticky thread Before You Post: Getting Database questions answered quickly (from the top of this forum) for the kind of info we need.

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: Data Refresh

    Change the location of the call to the data load. Maybe place it in the form Activate method.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: Data Refresh

    sorry for not given enough detail ...

    i mean when I put contact detail of database in the load event in form 1 and do editing in form2 the updated data will not change until I close form1 and reloaded again...

    so I am asking for event to put contact detail of database which will be update databse from hide event to show event...

    for example:Form1
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    
    Public Class Form1
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source =" & Application.StartupPath & "\db1.mdb"
        Dim Conn As New OleDbConnection(ConStr)
        Dim DataSet1 As New DataSet
        Dim SQLstr As String = "SELECT * FROM Table1"
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Conn.Open()
            Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
            DataAdapter1.Fill(DataSet1, "Table1")
            Conn.Close()
    
            TextBox1.DataBindings.Add("Text", DataSet1, "Table1.First_Name")
            TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Last_Name")
            TextBox3.DataBindings.Add("Text", DataSet1, "Table1.CPR")
    
        End Sub
    for example:Form2
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    Public Class Form3
        Dim frm As New Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim n As String = Me.TextBox3.Text
            Dim SavInto As New OleDb.OleDbCommand
            Dim ConStr As String = _
                "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" & _
                Application.StartupPath & "\db1.mdb"
            Dim Conn As New OleDbConnection(ConStr)
            SavInto.Connection = Conn
            SavInto.CommandType = CommandType.Text
            SavInto.CommandText = "UPDATE Table1 SET First_Name = '" & Trim(TextBox1.Text) & "' , Last_Name = '" & Trim(TextBox2.Text) & "' , CPR= '" & Trim(TextBox3.Text) & "'  WHERE CPR ='" & n & "'"
            Conn.Open()
            SavInto.ExecuteNonQuery()
            Conn.Close()
            MsgBox("Edit Succeeded")
            Me.Close()
            frm.Show()
        End Sub
    End Class
    I hope my Q is clear

  5. #5

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: Data Refresh

    Quote Originally Posted by GaryMazzone
    Change the location of the call to the data load. Maybe place it in the form Activate method.
    Thanks for reply GaryMazzone...

    I've tried Activated event but it is not working with my form !

    Code:
    Imports System.Data
    Imports System.Data.OleDb
    
    Public Class Form1
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source =" & Application.StartupPath & "\db1.mdb"
        Dim Conn As New OleDbConnection(ConStr)
        Dim DataSet1 As New DataSet
        Dim SQLstr As String = "SELECT * FROM Table1"
    
        Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
            Conn.Open()
            Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
            DataAdapter1.Fill(DataSet1, "Table1")
            Conn.Close()
    
            TextBox1.DataBindings.Add("Text", DataSet1, "Table1.First_Name")
            TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Last_Name")
            TextBox3.DataBindings.Add("Text", DataSet1, "Table1.CPR")
    
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width