[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bindingsource(Datastable) refresh

Posted on 2014-03-28
5
Medium Priority
?
344 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 64

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

834 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