Write Conflict error in MS Access 2010 when i try to assign a record source - ms-access-2010

I have SQL Server 2008 R2 linked tables in my MS Access 2010.
I have many forms in this MS Access database. Few of my forms gets Write Conflict error when I try to assign it to a SQL statement as record source after I have updated very same record by SQL statement (or assign some values on form programmatically and refreshed the form in module) as I have general function being called every time I enter certain text on one of the field on form and it gets updated some of the forms fields value programmatically.
I have a TIMESTAMP column in my table in SQL Server.
So after updating the fields on the forms, when I try to assign a new record like
Me.Recordsouce = sqlstring , I get a "write conflict" error.
I tried to set on button click before I assign a recordsource
Refresh
Docmd.RunCommand AcCmdSaveRecord
But they all throw the same "Write Conflict" error and asking me to drop changes.
Please help
Many thanks,

Related

Validation error while inserting Data to sql server

I am new in asp.net development.
I am trying to make a webpage using asp.net and SQL server 2008.
Just a simple page through which data will be inserted to the database. But I noticed it is taking duplicate records as well. So I used "Unique" constraint while the respective table and it is working fine.
But I wanted to show an error message which says "DATA already exists" after I am clicking the Insert button on the page.
Is it possible to check for duplicate entries and show the error while we are inserting data to a database?
without java-script or ajax please.
Please help with a code snippet.
Thanks in advance.
Regards.

Submit batch entry in datatables.net

I am using ASP.Net webform for my development and currently implement datatables.net. to perform some excel like data entry job. For more info, please go to http://datatables.net/release-datatables/extras/KeyTable/editing.html. I also added some add row and delete row functions at client side. Now I am stuck on how to push the entire table data to the server. It's look like excel and user can make the amendment. Whenever they plan to save the data, the user just need to click on save button and the entire table info shall be submitted to the server. For your information, no input textbox in this case because I am using keytable feature.
Please help!
Thanks.
I believe this datatables.net server side usage page has sServerMethod which may be fullfill your requirement. The data are passing in JSON format to server. In server side you can parse the JSON back to your DTO to update your data.
You can SqlBulkCopy for faster insertion of data in the database. You can search code for that on net.
You'll need to create an object collection of some kind in your handler to temporarily save the data into some kind of structure or object. What I did was append a row_id to the table row in the fnRowCallback of the Datatable, then grabbed it in the submitdata property of the Editable plugin, sending it to the server. Once there, I store it in an object, add it to the collection, and let editable update the table.
When you are ready to submit, fire it off, go to the handler, and send all of the data in the collection to the server as a mass update.

updating batches of data

I am using GridView in asp .net and editing data with edit command field property (as we know after updating the edited row, we automatically update the database), and I want to use transactions (with begin to commit statement - including rollback) to commit this update query in database, after clicking in some button (after some events for example), not automatically to insert or update the edited data from grid directly to the DB...so I want to save them somewhere temporary (even many edited rows - not just one row) and then to confirm the transaction - to update the real tables in database...
Any suggestions are welcomed...
I've used some good links, but very helpful, like:
http://www.asp.net/learn/data-access/tutorial-63-cs.aspx
http://www.asp.net/learn/data-access/tutorial-66-cs.aspx
etc...
Well,
you can store your edited data in a DataTable in session. and then pass this data table as a bulk insert in to the database. 2 options are available for this
if you are using SQL Server 2005 you can use OpenXML to achieve this, as i have stated here
if you are using SQL Server 2008 youc an use Table Variables like i did here.
i hope it helps
First way:
Create session variable that will contain your DB object (DataTable or mapped objects).
The GridView should work with this instance instead of sending the data to the database.
Once editing is finished you may take the object from the session and save it in the way you normally do.
Second way:
I would use javascript to collect all changes on the client side while he is editing as a array of objects (each object is separate row).
Once the editing done, you can create json string from the collection and pass it to the server.
If your json object configuration is same as server class then you can use JavaScriptSerializer to deserialize your string into collection of object.
After that, you can save your objects in the way you normally do.

How to refresh a page when record in db table get changed in ASP.Net 3.5

I have a page that contains a Gridview showing a record from a db table e.g. "tblEmployee".
If a record is inserted/updated/deleted in that table then I need my page to be reloaded so that the gridview will show the updated records. Records may be inserted/updated/deleted from any other application.
To rebind the gridview I have to reload the page. Suppose I open the page in my browser and no postback is done. After 10 minutes a record is inserted into the table by some other apps. How can I reload the page automatically, not manually by clicking refresh button when the records in db table changed? I am using Sql server 2005 as DB and ASP.Net 3.5(C#)
Please suggest how to implement this.
Thanks.
Here's two approaches... one using a trigger, the other using SqlDependency. I would recommend using SqlDependency, but I'm outlining another approach because you indicated trouble with SqlDependency.
Create a table with columns for table name and last update date. Create a trigger on tblEmployee to update that table on any insert/update/delete.
When the page is loaded, you'll want to store the current last update date for the table. Depending on how your page is setup, you could store it in ViewState or as a hidden field on the page. Then you'll need to poll for changes. There are many ways to do this. You could write a simple Page Method that returns the last update date, call it from JavaScript, and compare it to the date you stored in the hidden field. Or you could use an UpdatePanel with a Timer control and compare to the value you stored in ViewState.
Now this approach hits the database more than necessary. If that's a problem, use SqlDependency with SQL 2005 or greater. Create a SqlDependency and insert the current date into the Cache with this dependency object. Poll this cache item from the page as described above. When the dependency changes (OnChange event), update the cache item date again.
I see not other option that having a polling mechanism, i.e. using setTimeout+jQuery or ASP.NET AJAX Timer that pulls the information at intervals.
Basically what you want is for the server to notify the client that an update has occurred and in a web/ASP.NET application communication is always initiated by the client. So polling is your only option.
You could use the SqlDependency class:
Here's a getting started example: SqlDependency in an ASP.NET Application (ADO.NET)

Limiting records returned by a sqldatasource, using session variable in where clause

I have a web application which has a Sql Server database on the backend. As the site will be rolled out to different clients (or different virtual directories in IIS), each client derivative of the site will use the same backend.
There is an admin page where text on the site can be changed (enter text in a listview, and choose the page to select where that text will show up, and also you can see company-specific details in the other listviews. As this is a shared database, that means a client can see each other's data.
What I am trying to do is store the accountId (a guid returned from the database from login_authenticate), and stick this into session. I then retrieve this on the admin page, and I want to use this value (But it's always 0000-0000 etc), to limit the records returned in the listview.
Is there an example of this? Also, how can I set the default value (this is in the where clause of SqlDataSource), to programatically what the account id is (so I can give me all records = what the current accountid is, or perhaps, what the login is - this is stored in the account table).
Thanks
This is what I tried.
What I am confused about, though, is whether the where clause, when using a session object, is getting an object that I have written the code to retrieve from the session, or an object I have only added but not retrieved. I get the accountID when logging in (verified via stepping in - obviously - or the login will fail).
I will try again with storing the object in session # the login page when I have just retrieved the accountid variable, and then retrieve it on another page.
For some reason I keep getting 0s so I will look at this in my application.
It sounds like your method should be working. I would follow a debugging process:
Check that you are getting the accountID value from the database. Print it on screen immediately after retrieving the value for the first time.
If this is working, store the value in the Session and immediately retrieve it, and check that you are getting the value back.
Create 2 test pages, one where you set the Session variable and another where you retrieve it.
I know this seems really basic, but the failure is being introduced somewhere in the above 3 places. If you can find which step fails, you will be able to fix it.

Resources