iliekater Level: Master
 Registered: 04-02-2005 Posts: 122
|
My AdoDc control insists on updating a field in my data base !
Lately I decided to change the code in a program of mine that uses an AdoDc control to connect to an Acces data base and also a DataGrid control in order to show the contents of the data base file (of a specific table , ofcourse) .
I wanted to change the code , becoue up to now it was designed for the AdoDc control to connect to a specified file , that is the path always being the same . But since the program will be installed in various computers and each user may decide to install on a different path , I no longer can rely on a static path .
Thus , instead of assigning manually the properties the AdoDc controls (connection string , record source etc) , I have to do that by code .
First , when the program is firstly loaded , I hav a routine that determines the installation path (I call the variable ontaining the path Motherpath !) .
So , when the form containing the AdoDc control is loaded , the program already knows its installation path and the path of the data base file (MotherPath & "\Resourses\DataBases\Customers.mdb) .
Up to now , I haven't noticed any problem .
Here's the code at the Load section of the form :
Private Sub Form_Load()
DataBaseString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MotherPath & "\Resourses\DataBases\Customers.mdb;Mode=ReadWrite;Persist Security Info=False"
AdodcCUSTOMERSDATA.ConnectionString = DataBaseString
AdodcCUSTOMERSDATA.CommandType = adCmdTable
AdodcCUSTOMERSDATA.RecordSource = "Table_Customers"
AdodcCUSTOMERSDATA.Refresh
'''
TextBoxDEBUGSOURCE.Text = DataBaseString
End Sub |
As far as concerning the AdoDc control itself on the form , it has no property set manually (in fact I deleted the old one and added a new one in order to be sure) .
There has to be something wrong in the above code , becouse when the program runs and the form is loaded , though the DataGrid is populated susscesfully , the program tries to change the value in row 0 and column 0 of the DataGrid ! What in the world makes it believe I want that ? ! Here's a photo indicating that :

I managed to take the snapshot so that the cursor is also visible within the cell . I can't understand why this is happening . There are also 2 things : 1) The DataGrid is set to not allow Write , only allow Read of the data base file ; 2) The value that the prigram tries to change is actually from the ID field of the table of the data base , which means it can't changed eitherway .
In fact , if I try clicking on any row in the DataGrid control , I get the following error message :

Which sais :
"Cannot update 'ID' . The field is not updateable .
Anyone knows what's going on ?
|