New SQL table value won't stay - sql

I am new to dealing with SQL Express DB tables. I have a Windows application that gives the user a textbox that is bound to a value in my dataset (ds) which reflects my SQL table (Specs) field. The user can change the numeric value of the textbox and I can see by setting breakpoints that it created the new value in my dataset (I used MsgBox(Ds.Specs.Rows(0).Item(10) to determine this to be true). However, when I open the application back up, the OLD value appears again in the text box. It is like my dataset is not updating the SQL server table.
Again, I am new to SQL tables and allowed the wizard to create all my insert/update/delete statements which appear to be in place. Any idea why my values won't stick?
Thanks.

Once the element is put in there has to be a database submitChanges() function that has to be called to actually store your new information Im not sure exactly what the command is in VB but in c# its OnItemSubmitt(). Its all .NET so the command should be the same.

In .NET, you'll want to be sure to call the function AcceptChanges() on the Dataset object. This saves information that has changed since it was loaded or since the last time AcceptChanges() was called.
Some information can be found here on the function, and an example of its use.

Related

How to copy from table design from database to another vb.net access

The aim is when updating the application and update the access database without altering the data so update by update only the new tables or new columns so i want to copy the exact table with it's structure to the old database vb.net and access database.
what I've tried is detecting the differences between the old database and the new one by getting in combobox1 the only missed table and in combobox2 the missed columns in the old database in exact table already there in both database and get it's data type .
so i want to copy the entire table and then create only missed columns
thank you
There is not a built in tool to do this.
But, worse yet, there is no "generate" change scripts in Access
(Like say with SQL server).
So, how do you approach this issue? What do some of the accounting systems or commercial programs that use ms-access as the database?
Well, you have to build a kind of "up-grade" system in your software.
This means two things:
To add a new column to a table (for example), you NEVER go open up the access database with access, but "add" or "write" the code to add that field in question.
In fact, I had an applcation deployed out in the field - many desktops.
So, I had a code module called upgrade. And each time I needed a new field or whatever, then I would write the code to add that new colum.
AS LONG as I always added things into that code module, I was ok. (never break the rule for adding new fields, tables or even increasing the length of some field? - use code).
And it became quite easy after I had some code written. I would in fact often cut + paste a previous bit of code to add a new column to a table.
However, after about 5 years, that messy code module had 800+ lines of code in it!!!
But, I ALSO realized that MOST things like adding a new column or whatever? Same code over and over.
So, what I did next was built a "upgrade" table. It looked like this:
Version action SQL RunCode
2.5 AddTable tblCustomers
2.5 AddField "sql here to add table"
etc. etc.
So, I had a version number, and then I compare against the up-grade table. I had "action", and the code would simple loop this table, and do whatever.
So, for example, to add a field, you can use access "DDL" command (data definition commands - most SQL systems support this, and so does Access).
so, say like this:
' any new table code goes here:
If lngVer < 1148 Then
' add event Invoice text option
ExecuteSQLNR "ALTER TABLE dbo.Events ADD InvoiceText ntext NULL"
ExecuteSQLNR "ALTER TABLE dbo.Events ADD HideEventDate bit NULL default 0"
Or, say to increase a column lengh from 50 to 55
db.Execute "ALTER TABLE tblGroupRemind ALTER COLUMN Anotes text(255)", dbFailOnError
As noted, since oh so many the commands were VERY similar, then I started putting that information into a table, and then I would execute the required upgrades in a loop.
For a whole new table? Well, I thought that was too much code, so I always included a blank empty database - and for new tables, I would place them in that upgrade.accDB table - and "transfer/copy" the table from that upgrade database to the real one. That way, I could with great ease create a whole new table, and create in Access designers, and then add/copy that table to the "upgrade.accDB" database.
As noted? The above ideas an approaches work quite well.
In fact, over time, I found it LESS hassle while coding away to add the new column or whatever LESS effort then having to open up ms-acces, and then the table, and then the designer and make the changes.
However, the BIG issue with above?
Well, you have to get all users at least upgraded to your EXISTING schema, and there is no automated tools.
in fact, before I had any automated tools? I would open up note pad, and if I added some field to some table? I would simple type into note pad that new field in such and such table is required).
Then, when on customer site, I would open up their database, and then go look at the note pad document for the list of changes I was to make. (that is what I was doing before I started automating the process - and of course it not always practical to be "on site" or have the customers database.
But, ONCE I had all of the above working?
Then during development, I would open up my "upgrade" database, add the new row and action (new table, new column, (and more).
I even had a column that defined the function to run AFTER that one command. I mean, quite often when you add a new column, or change somthing in a table, often you need to copy data, or at least process some data after you make that change.
Once you get above going?
Then you simple NEVER make changes in the data tables directly, but use your "system" for this. And that works REALLY well.
For one, a customer could open up a older data file - say one from 4 or 5 years ago. The applcation version number would be detected, and then the upgrade code would run all though the versions to update that database. (and I did this automatic on startup - so they never even knew such a upgrade had occurred).
So, you just have to make sure that for each change you make, you put that code in your upgrade system, and you are done.
But, for existing systems? You have to look at what changes you made since last deploy, and write out the "ddl" commands (the alter table SQL commands).
There is no automated way of doing this.
As FYI?
One of the BEST and more valuable free tools in Visual Tools is the SQL server compare utility. It will not only automatic detect and tell you the changes between two SQL server databases, but will also upgrade for you. (very nice).
But, such a system is not available for Access. In fact, so valuable is that utility for SQL server, you might consider upgrading from Access to SQL server for this applcation. With that utility? I can work local, add fields, columns, tables and even stored procedures to that SQL database. When I am on site (or even by VPN), then I run that compare tool - it shows the changes, and ALSO has a button to update the target schema.
I don't know of a automated "schema" checker and updater for Access.
So, what I suggest for above ONLY works if you put such a system in place, and THEN as a developer always make your schema changes to your upgrade system, and never directly in the database with ms-access.

How to query access table with a subdatasheet that requires parameters

I have been tasked with creating a method to copy the contents of an entire database to a central database. There are a number of source databases, all in Access. I've managed to copy the majority of the tables properly, 1:1. I'm using VBScript and ADO to copy the data. It actually works surprisingly well, considering that it's Access.
However
I have 3 tables that include subdatasheets (to those that don't know, a subdatasheet is a visual representation of a 1 to many relationship. You can see related records in another table inside the main table). When My script runs, I get an error. "No value given for one or more required parameters." When I open Access and try to run the same query that I've written in SQL, It pops up message boxes asking for parameters.
If I use the query wizard inside Access to build the select query, no parameters are required and I get no subdatasheet in the result set.
My question is this: how do I write a vanilla SQL query in my VBScript that does not require parameters and just gives me the data that I want?
I've tried copying the SQL from Access and running it through my VBScript and that doesn't seem to do the trick.
Any help is greatly appreciated!
As it turns out, you need to make sure that you've spelled all of the field names properly in your source query. If you've included additional fields that aren't actually in the source or destination table they'll need to be removed too.

Fields added to SQL Backend lock the records in MS Access

We have a database that is using a SQL Server backend with a MS Access and Filemaker frontend. It has been working fine. I added two fields to one of the tables today, one datetime field and one bit field.
When the table was updated in Access they can no longer edit a field in the records. A Write Conflict error comes up
"The record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other user made. Copy the changes to the clipboard will let you look at the values the other user entered and then paste you changes back in if you decide to make chages.
The save Record option is grayed out.
Any ideas what the problem could be?
Is the bit column nullable? MS Access can show those symptoms when dealing with a nullable bit column.

Update multiple records in SQL from Access without error "The data has been changed"

I am working with an ODBC connection between Access 2013 front end and a SQL Server 2008R2 back end. I have both “Datasheet” and “Continuous” forms that display multiple records which are sorted on an “order” field (integer).
The record source of these forms is a query (an Access local query right now, but I don’t think that switching it to a SQL Server view will solve my problem). Users use these forms to set/update the order of their records for reporting purposes.
My problem: the forms are updateable, but keep throwing the error
The data has been changed. Re-edit the record.
I know this error can be solved by setting the respective form to re-query after every update, but that is equally frustrating to the user because then their records are constantly re-sorting on them as they are trying to set the order (and the form "blips" after every entry).
(I have the field "Timestamp" in all my tables. I know a similar error is raised if one does not have this field in a SQL BE database linked to an Access FE.)
What is the best way to allow the users to update the order of all their records without the form resorting on them? (I would like to keep the “sort” in the query on the “order” field so when they open the form next time it displays the records in the order they specified.) I’ve read about using unbound forms with a stored procedure to update the SQL data, but this seems to be useful for one record at a time. Could I use a temp local table, and then do a batch update with a stored procedure? If that is the best answer, I also ask for some example code to get me headed in the right direction. :)
A simple answer! Add Me.Refresh to the AfterUpdate event on the form or subform. Then when a user does want to update the form based on their new order, they can click a "refresh" button that is set to Me.Requery or Me.Parent.Requery depending on the form or subform, respectively.

Access Form Textbox as Input query to ODBC source returns empty dataset

I have an Access 2010 utility that is designed to query an Oracle DB via ODBC connection as Linked Tables. I created a simple form with two textbox's and a command button. The command button launches VBA code "DoCmd.OpenReport".
The report query Where clause looks like this:
WHERE (((PRODLAW_ITEMLOC.LOCATION)=[Forms]![frm_Qry_ByItem&Loc]![txtLocation]) AND ((PRODLAW_ITEMMAST.ITEM)=[Forms]![frm_Qry_ByItem&Loc]![txtItem]));
the values of txtItem and txtLocation are the user supplied values from the form.
This returns an empty dataset as it is now. If I query a local table, (using a single ODBC query to extract all possible values into a single local table) this method works without any issue other than the 8-10 minutes it takes to refresh the local table. If I replace the query criteria "[Forms]![frm_Qry_ByItem&Loc]![txtItem]" with a simple direct value like "1234" (assuming 1234 is a valid item number), it works without issue.
I've tried to explicitly convert the value of the textbox like "Cstr([Forms]![frm_Qry_ByItem&Loc]![txtItem])" but it made no difference. As this is a query, I can't simply create a breakpoint and examine the properties of the variables so I'm left scratching my head. I've spent hours searching SO and other sites for clues but found nothing related.
Please advise. Thanks!
mfc