How to refresh a dataset to reflect external changes to the database? - vb.net

In a WinForms application that uses a dataset from a data source created using the Data Source Configuration Wizard and connected to an Access database. How can I refresh the dataset at run time to reflect changes (data changes only, no structural changes) to the database occurred outside without closing and reopening my application?
Thank you ahead of time for your help.

Call the .fill command on the tableadapter that the wizard should have created.
By default the code is placed in the load event of the form that you added the tableadapter and dataset to, so either copy paste or creat a new sub and call that.
Edit:
There is a clearBeforeFill property of any tableadapter listed under the TableadapterManager in the Form designer if you added it via the designer, if not then you'll have to set it in your code behind.
in the code behind there are several events that can occur on your binding source, I would suggest putting the needed code on the currentItemChanged event in order to commit changes in real time.

Related

connecting new column to visual studio through accdb

I have created a winform app connected to an access database as datasource ,
but now i have added a column in access database & now i have to provide the same field in winform for data entry purpose.
But now in my data source the new field is not visible even after refreshing .
any help in solving this.
The simplest way to do this is to open the dataset, right click on the relevant table adapter (MSdiesTableAdapter), choose Configure and then go through the wizard, adding the new column to the SELECT sql. When you finish the wizard the new column will appear in the datatable.
It won't have appeared in any databound grid etc - you'll also have to go to those grids and do an "Edit Columns" and "Add a New Column", choose "DataBound Column" and pick the new column. You can also, as a quick trick, remove the "DataMember" setting from the bindingsource the grid is bound to, then put it back
Microsoft never intended for DataSets and databases to be perfectly aligned; the dataset is your client side store of info and it may have more or fewer columns than the database, and have stuff it calculates itself locally, or relationships that are different to the database. This is why it needs manually adding and working through

Access runs function in control's RowSource when form opened in Design View

I have an Access 2007 form which contains a combo box with the following Rowsource:
SELECT qryProjectsIHaveAccessTo.projID, qryProjectsIHaveAccessTo.projName
FROM qryProjectsIHaveAccessTo
WHERE (((qryProjectsIHaveAccessTo.projSupportTracker)=False));
The query qryProjectsIHaveAccessTo uses a user-defined function as the criteria for one of the columns. This function detects if a Startup routine has been run, and if not runs it.
The problem I have is this: if I SHIFT+open the database and open the form in DESIGN mode, for some reason the user-defined function starts running. This then causes errors as the Startup routine it calls tries to open a form (presumably Access cannot open a form while it is in the process of opening another form in Design mode) and sometimes I am not able to CTRL+BREAK out of it.
The same thing happens when I go to save the form in Design mode.
If I remove the RowSource string from the combo box, this no longer happens. But why would a function which is called in a query included in a control RowSource get fired when the form opens in Design Mode?
Any ideas anyone? Thanks for reading!
When you open a form in design view, Access validates that the form record source is still there, and that all the query fields that are bound to form controls are still there.
If some of these checks fail, Access shows the small green triangle on the bound controls with problems.
While doing this check, it runs the UDF in the query.
As was said in the comments, calling a startup function does very much not belong into UDFs that are called from a query. Put it into a function that is called by an AutoExec macro.

Visual Studio - when to call update on a tableadapter

I'm new to Visual Studio - migrating from Microsoft Access and Dynamics AX where updates to physical tables happen pretty much automatically for a simple data grid.
In my Visual Studio VB form project I have a datagrid component bound to a tableadapter. I can double-click a cell and edit the contents, then move to another row. But my changes are not being committed to the dataset's table.
Even though the tableadapter has an update method, apparently it is not called automatically. Do I have to call the tableadaptor's update method to save the user's data changes in the grid?
If so, how do I detect when datagrid cells values have been changed? Or do I simply call update every time the user leaves a row and let the update query run even with no changes?

How Does Visual Studio/VB Create and Initialize a Table Adapter?

I have a very simple Windows form application that uses a data set. I am having trouble figuring out how Visual Studio creates a new Table Adapter object and then initializes that object through its insertion of initialization code into the .Designer.vb files. My problem is I have inadvertently caused this to happen through some series of commands I do not remember, and am trying to figure out how to re-create what I did.
For example, if I want the data set to be used by a form, I know this goes in the form's Designer.vb module
Friend WithEvents StreetsTableAdapter1 As WindowsApplication1.DataSet1TableAdapters.streetsTableAdapter
However, this line alone won't instantiate the table adapter object.
As to the data set, I've created a one; configured one of its table's table adapters to use SQL queries; tested those queries; and they work.
I'm more interested in what Visual Studio writes to create the new object rather than the keystrokes to do it, because I'd like to know what's going on underneath the covers, rather than relying on keystroke magic.
I have a workaround
Me.StreetsTableAdapter1 = New DataSet1TableAdapters.streetsTableAdapter
I've added this to the form's .Designer.vb file. I'm still trying to figure out what I did in Visual Studio to get all this initialized through running some specific commands.
A pointer to an example would help, as well as the steps to make this happen. Then, I'll examine what Visual Studio does, so I do not get stuck again.
The easiest way to create the table adapter on your form is to let Visual Studio do it for you. In the toolbox "DataSources", you should see your current data. You can expand the nodes and drag the fields/tables to your form. This will create the table adapter and everything needed behind the scenes.

RDLC Report Data doesn't update to reflect changes

On my RDLC page, the "Report Data" window shows a custom dataset that it pulls fields from to display. I've modified this DataSet with some additional tables. However, these tables aren't shown and therefore I'm unable to select them for use in expressions (in the Expression window, under Datasets, there are only the tables that were originally there, not the additional tables I've added).
Refreshing the data source doesn't do anything, and if I right-click on it and select "New Dataset", I'm unable to select the parent data source (it doesn't appear in the drop down list). What I mean is, if the data source is called "MyDataSet", and under that are other DataSets, if I right-click and go to "Add Dataset", it brings up the dialog box but "MyDataSet" is not in the list of available Data sources, even though I'm specifically saying I want to add a datatable to that data source. The other, existing, datatables list it under the data source, but new ones do not.
How do I refresh the data source so I can access these new tables in my report?
This is an old question, but I was having this problem too and I'll mention my answer for future googlers.
In the Report Data Window (which automatically appears for me when I am editing a .rdlc file), I had to Refresh my Dataset (same name as the DataSetName in the Tablix in my .rdlc Report), and then that updated the XML of the .rdlc file. The new fields are then available to me.
I have the same problem with Visual Studio 2010 Premium. You must do this step:
Re-build the project that contain your Business Object
Restart Visual Studio
Refresh your DataSet (Report Data --> Right click on DataSet --> Refresh).
I managed to get this working (for SSRS in C# using a Dataset that points to a Stored Procedure) by:
hitting Shift+Alt+D (which opens the "Data Sources" window)
In Data Sources, select/click the table you want to update
At the top of the window there are icons (I'm using VS2012). The 2nd from the right is "Configure Data Source" - click it and it will open a new wizard window that will appear to be refreshing everything.
UN-check the column that is no longer applicable and/or check the new column (if the values aren't already checked/unchecked).
Go back to your "Report Data" window (Ctrl+Alt+D) and right-click on your Dataset and then click "Refresh".
All the columns should be updated at that point.
Have you tried rebuilding your project? I had to do this after changing any business object.
I had this issue for hours on VS-2008. Tried everything and at the end what worked was just to close and open it VS again.
I can confirm that just closing the solution and reopening it, with later refreshing the DataSet from Report Data window worked for me.
Seems like there is no need to restart VS.
I got the same issue in visual studio 2012. I solved it, here is the steps,
Press Ctrl + Q and type Report Data (If No Report Data window available)
Expand Data Source node to find the data set (I have used Data Set)
Right click on the Data set and select Refresh (Simply refresh the data source)
Delete the dataset and again add it with ur query or usp...
If you are using a database source the likely culprit is that you didn't create the query with select *. Without the * the query will always be static and new fields won't appear. HTH
For visual studio 2010
Open Your Data Set (.xsd file)
Right click on data set click on configure
Click on Next Next than finish
On your dataset click refresh than Changes willbe display.
Sounds like same issue is happening on VS2019. I could resolve the issue by only restarting Visual Studio, nothing else worked!
This is the only solution worked for me.
After updating the DataSource properly, open the .rdlc file in NotePad and add the newly added Field manually. Then it will be available to use in the report.
Had the same in VS2019 using an object datasource, right click and refresh on the dataset in the Report Data window had no effect until I changed the build configuration from x64 to Any CPU, then it worked as expected. Once it updated changed the build back and all was well - not at all flakey!
As ChanthJ said -
It is the only solution worked for me.
After updating the DataSource properly, open the .rdlc file in NotePad and add the newly added Field manually. Then it will be available to use in the report.
steps
Assuming you Data source is fed by stored procedures, the following worked for me (On Visual Studio 2017): -
Make the necessary changes in the source stored procedure in the Database(new Field Names etc.).
Double click the .XSD file from the Solution Explorer to open it
Delete the associated Data Table / Table Adapter.
Add the Table Adapter back into the .XSD file (the changes will be reflected)
Save and close the .XSD
Open the .rdlc report designer.
Press "ctrl+Alt+D" or Click View > Report Data.
Expand the Data Sources node.
Right Click the Data Source.
Select "Refresh".
Expand the Datasets node.
Right Click the Data Source.
Select "Refresh"
The changes will now reflect and be available for selection on the .rdlc
report designer