Solved

bindingsource(Datastable) refresh

Posted on 2014-03-28
5
331 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

18 Experts available now in Live!

Get 1:1 Help Now