Solved

bindingsource(Datastable) refresh

Posted on 2014-03-28
5
332 Views
Last Modified: 2014-03-31
I have a bindingsource that creates a datatatable programically.  I do not use a table adapter.  I need to know how to get the most current records without restarting the program.  I have tried BindingSource.ResetBindings(false) and it did not work.The code I am using is:

        '// create database connection
        Dim cn As New SqlConnection("Server='" + sqlseverlocation + "';Initial Catalog='" + sqltable + "';Persist Security Info=True;User ID='" + sqluname + "';Password='" + sqlpass + "'")

        '// define query and populate datatable
        Dim adap As New SqlDataAdapter("Select TOP 100 Item, AGENCY, Unit, Location, [Activity Code], [Case #], Month, Day, Year, Received, Dispatched, InRoute, Arrived, ToHosp, ArrvHosp, Completed, Remarks, AddNum, SeneMileage, HospMileage, TotalMiles, Operator, [Enter Info], Address FROM COMMUNICATIONS WHERE AGENCY='" + fdname + "' ORDER BY Item DESC;", cn)
        Dim dt As New DataTable

        adap.Fill(dt)

        '// configure binding source
        BindingSource.DataSource = dt
        BindingSource.RaiseListChangedEvents = True

        '// bind textboxes to columns in the datatable

        txtCasenumber.DataBindings.Add(New Binding("Text", BindingSource, "Item"))
        txtUnit.DataBindings.Add(New Binding("Text", BindingSource, "Unit"))
        txtCaseNum.DataBindings.Add(New Binding("Text", BindingSource, "Case #"))
        txtStreet.DataBindings.Add(New Binding("Text", BindingSource, "Location"))
        txtMonth.DataBindings.Add(New Binding("Text", BindingSource, "Month"))
        txtDay.DataBindings.Add(New Binding("Text", BindingSource, "Day"))
        txtYear.DataBindings.Add(New Binding("Text", BindingSource, "Year"))
        txtreceived.DataBindings.Add(New Binding("Text", BindingSource, "Received", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtDispatched.DataBindings.Add(New Binding("Text", BindingSource, "Dispatched", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtArrived.DataBindings.Add(New Binding("Text", BindingSource, "Arrived", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtToHosp.DataBindings.Add(New Binding("Text", BindingSource, "ToHosp", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtArrivedHosp.DataBindings.Add(New Binding("Text", BindingSource, "ArrvHosp", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtCompleted.DataBindings.Add(New Binding("Text", BindingSource, "Completed", True, DataSourceUpdateMode.Never, "", "HH:mm"))
        txtActivityCode.DataBindings.Add(New Binding("Text", BindingSource, "Activity Code"))
        txtSceneMil.DataBindings.Add(New Binding("Text", BindingSource, "SeneMileage"))
        txtHospMil.DataBindings.Add(New Binding("Text", BindingSource, "HospMileage"))
        txtTotalMil.DataBindings.Add(New Binding("Text", BindingSource, "TotalMiles"))
        txtoperator.DataBindings.Add(New Binding("Text", BindingSource, "Operator"))
        txtDetails.DataBindings.Add(New Binding("Text", BindingSource, "Remarks"))
        txtAddress.DataBindings.Add(New Binding("Text", BindingSource, "Address"))

Open in new window

Any help is greatly appreciated.
0
Comment
Question by:russell12
  • 3
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39963124
How do you determine "the most current records" from all the rows in the data table?
0
 
LVL 2

Author Comment

by:russell12
ID: 39968414
ok i have solved this issue.  but to answer your question, what i mean from "the most current records" was if user 1 added a record i would need it to "reqery" the database to get the most recent information.  The way I am achieving this is by using txtCasenumber.DataBindings.Clear()
txtCasenumber.DataBindings.Add(New Binding("Text", BindingSource, "Item"))

Fernando Soto, I have seen you respond on some of my post, so I would like to thank you and give you the points.  So I want your opinion if this is the best way.  Sorry I did not explain it clearer in the initial post.  Again I thank you for being such a great help!!
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39968437
Yes the way you are doing it will cause the binding to reread the data source and get any new values. That is fine.
0
 
LVL 2

Author Closing Comment

by:russell12
ID: 39968445
Thanks again for helping me.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39968451
Not a problem, always glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now