Solved

bindingsource(Datastable) refresh

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

772 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