[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

bindingsource(Datastable) refresh

Posted on 2014-03-28
5
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 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