Has anyone had any success with adding a row to an (external) Access 2.0 database. My code is:
' *** create a new row by calling the NewRow method
Dim thisRow As DataRowthisRow = dsACCIMAGE.AccImageTable.NewRow()
' *** manipulate newly added row using column name ' note: can alternatively replace column name with column index ' e.g. thisRow(3) = SelectedPathName ' Code for the 1st column goes here after auto-counter updating is resolvedthisRow(
"ImageDateTime") = somedate & sometimethisRow(
"ImagePathName") = SelectedPathNamethisRow(
"ImageFilename") = SelectedFileName ' Code for the 5th column goes here when all other issues resolved ' *** now add the rowDsACCIMAGE.AccImageTable.Rows.Add(thisRow)

VB 2005 Express/MS Access - row is not being added
JeffreySax
hi, Allen
you are welcome my friend, mark the answer for this question or it will stay unanswered question
Best regards
Flinders
Hello again Shak!
Yes, that did it! My Access database is now being physically updated - even the counter-type field is being automatically incremented and populated.
I have been sifting through the MSDN documentation for days, and not once did I see any discussion a further line of code to physically update the database.
Well done Shak, and thanks.
balance
Hi Shaka,
A month ago you helped me out with a problem quite successfully and I thought it was one hurdle I was over. Now after travelling 'round the VB Basic universe I am back with almost the same problem in another program. Simple little MS Access table (external) with 5 columns. Even in a test proj manner, I cant recreate my success - it will not accept the 1st executable line of program text. Within VB 2005, I can see the Data Connection, Table, Columns in the Database Explorer and the corresponding Dataset and Table in the Data Sources. Yet when I code..
Dim thisRow as DataRow ' it doesn't complain about this line
thisRow = datasetname,tablename.NewRow() ' response is "reference to a non-shared member requires an object reference
Because the original program (which worked) is quite complex now, all I can suspect is that there is some linkage or whatever that I have left out between the Database Explorer and Data Sources. I've even tried using a code snippet which involves ODBC but that just ended up in a hell of a mess and to me completely non-understandable.
If you can point me in the right direction with this problem I'll send u a brand new (logical) Rolls Royce.
Secondly, if anyone knows of a VB2005Express/MS Access reference manual, I'll include a (logical) 1000 litres of fuel.
Allen (sweltering in 35C heat in Melbourne)
rhoule
G'day again Shak,
Much success has been achieved. Following your instructions, I created a new project and copied my application code into it and rebuilt the form objects and such. ALL errors have now disappeared and the application compiles and runs ok at least as far as i can see with the little checking I've dones - so your comment about the designer is certainly validated, in that it doesn't clean up after itself, lol. That's a bit like me, I had similar probs a few weeks ago with a small test proj and the designer wouldn't even start. I fixed things then, as we have just done again today. My only remaining minor problem is that i still have the binding source listbox on my form and of course reference to it in the area below the form. Inspection of the latter shows it is linked to my datasource. Ideally I'd like to remove these but am unsure how. A quick and nasty way would be simply to make the listbox invisible (presuming, i can do that). Is there a clearner way
So for the benefit of the MVP people.
(1) the TableAdaptor/Designer has a self-maintenance problem (possibly only on removal of the TableAdaptor).
(2) I re-found a minor annoyance when I re-named a status label in that the change is not immediately reflected on the form when you make the change and press the tab key. It requires u to Save the file/s before u see the result. This has had me scratching my head before and found the answer by accident. It's just that I only notice this inconsistency with this particular control - the status label.
Lastly, I've now adopted a new standard to ensure the machinery doesn't get confused, by always making my naming of windows filenames/dataset names/tablenames/column names different. Helps me in reading the code too.
All of the above was from a MS Access/VB 2005 Express perspective, but some may also aplply to SQL Server Express users.
Again, thank u for pointing me in the right direction with that one Shak. I'll leave the closing off of this thread until we discuss whether there is a clean way to address the "binding source" removal.
Allen
Gabriele38
hi,
some times when you delete things like that the ide doesn't delete them from the designer file and will give you this error once it happend to me so i started a new application and copied my code and added a new controls to the forms because particulary if it came to tableadapter, you don't know how much i hate this control all my troubles come from it, i write the sql statments and use the connection i don't use table adapter except with 2 conditions ( it was generated with the dataset , during project start up ) after that i get away from my table adapter and use sql and connection string ... etc
try to trace you table adapter in designer you will find it add hell of code to your project so i avoid it myself
best regards
JainMohit
O man i couldn't even read your code i don't know what does this $ mean
the only lines i could read was those 2 lines
Dim thisRow As DataRow
i don't know why did you repeat the table name in 2 lines, you should write it directly as what you mentioned in your previous post like for examplethisRow = KEWV2DataSet.tblErrorLogTemp tblErrorLogTemp.newrow()
Dim thisRow As DataRow
thisRow = KEWV2DataSet.tblErrorLogTemp.newrow()
' then you start to fill that row with data
thisrow("columnName") = value
if your database doesn't accept null and doesn't have default value it will through exception
hope this helps
Mike Houglum
Good Morning Shak,
I will eventually have to follow what u suggest I guess if what I was trying to do is not accepted by VB2005. Whenever I and possibly many other newbies see mention of Classes, Instances, My, Me, I automatically recoill like I'm being dragged off to the dentist for some drilling. I am quite able to accommodate OOP's concepts in MS Acess and still use a procedural style. Doesn't VB2005E accommodate this.
My little testbench project could not have been simpler. Why does intellisense then invent other "things" and then confuse itself to the point that the programmer can't proceed. Why do I also need some object on the form bound to (ugh) bindingsource
What confuses me even more is that a month ago we tried exactly what we are trying now, but then it worked and now it doesn't!
It's like having to deal through a mysterious intermediarry rather than getting hands on and obtaining a full understanding in the process. Eventually I will look at these new (to me) concepts but right now I want to get up and running, knowing what I am doing and even more importantly being able to debug it if necessary. I'm quite comfortable with assembler, & 2nd and 3rd generation languages, oops and relational databases, but the required solution VB proposes leaves me feeling uneasy and not at all confident of my productivity.
It's not so much the what VB wants me to do but the WHY!
Now none of this detracts from your kind assistance. I'll just have to get out the many reference texts I have and read a few thousand pages to find what VB makers should be saying "up front" in a simple and understandable step by step nature.
Now I've gone and gotten the dismals lol, guess I'll just spend the rest of the day looking for something I can understand, like the Higgs Boson.
Thanks again mate.
darwind
hi, Allen
i'm still newbie too and still learning as well, believe it or not you will get the concept eventualy just keep reading but don't miss practice this is how its going, the ease of OOPs is the same as its problem, to biggest benefit of OO is to change anything in your application easly without rewriting it, its the same thing that make problems you can change something when you don't pay attention it will make you keep turnning around yourself to figure out what you have done and remember when you working in a program you keep changing it so may be you changed something and didn't provide it with the nessary changes
the last thing class and object your form is a class(simply your code) when you want to open your form you say form1 f = new form1 when you use the word new then you made instance(object) of this class , there are lots of things you use like that dim dataset1 as new dataset so you creat instance of your dataset class actualy i prefer the word instance than object anyway
actualy intellisense is great you will not appreciate it except if you wrote code on text file and compile it you will really respect intellisense very much and its actualy doesn't confuse itself, there is something so important is the naming of your variable this is the most important part of programing in my opinion don't abbreviate names much make it meaning full to you in a way you can distinguish between things in your project
best regards
Nick Foster
Hi Shak,
Thanks, i used an old trick, took the dog for a walk then came home and read the book "MS VB 2005 -Build a Program Now", particularly pages 148-151. How many times have I said to myself "when in doubt - read the blasted book", lol.
I then recreated the ds and the 4 thingos as I call them, on the surface beneath the design area - table adapter, binding source, navigator and dataset. I removed the navigator because i don't need it, and also removed all the fields from the form as I don't need them. I renamed the highlighted object names in the application and all of my application errors (4) have now disappeared. Half way there. There are still 4 remaining error messages in the designer. This is definitely an area I am uncomfortable with. It seems to be related to class definition to a the load form event which I had removed.
The remaining errors are:
Error 1 Type 'KewV2.KEWV2DataSet' is not defined. C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\KewV2\KewV2\KewV2.Designer.vb 37 31 KewV2
Error 2 Type 'KewV2.KEWV2DataSetTableAdapters.tblErrorLogTempTableAdapter' is not defined. C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\KewV2\KewV2\KewV2.Designer.vb 38 46 KewV2
errors 3 and 4 are the exact same as the above but at lines 199/200 in the designer file.
some time ago i found out how to get into the actual designer code and made some changes - i think i got into trouble so i haven't dared go near it since. For info, the project name is KEWV2. Now that I have cleaned up my mess somewhat, does the problem seem any clearer to u I still have the dataset and table adapters thingoes showing beneath the design area.
Allen
Morten Hvidberg-Knudsen
'error code obtained from index equivalencing
'---------------------------------------
Dim errorcode$(99)
errorcode$(0) = "[E9999]"
errorcode$(1) = "[E0001]"
errorcode$(2) = "[E0002]"
'errorvalue = index of errtexts$
'---------------------------------------
Dim errtexts$(99) ' max 100 strings indexed 0-99 provided for
' 123456789012345678901234567890123456789012345678901234 (1-54)
errtexts$(0) = "Programming error - errorvalue = 0 - aborting"
errtexts$(1) = "<10 contiguous chars in chars 1-10 in file - aborting" '(1-based)
errtexts$(2) = "1 or more files had illegal headers - aborting"
'date and time
'---------------------------------------
'subroutine initialisation
Dim datenow = Format(DateTime.Today, "dd/MM/yyyy")
Dim timenow = Format(DateTime.Now, "HH:mm")
'write to temporary MS ACCESS Error Log
'create a new row by calling the NewRow method
Dim thisRow As DataRow ' next 2 lines flagged by intelllisense
thisRow = KEWV2DataSet.tblErrorLogTemp ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
tblErrorLogTemp.newrow() ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'listbox programming goes here
Me.lb1.Text = errorvalue & name
End Sub
Gerrit Brehmer
hi,
this code doesn't add any code to database its just add the row to your dataset and thats it if you didn't save it , it will not be added
you can call your table to update the data in your database
adapter.update(thisrow)
hope that helps
Dolfandave
hi, Allen
it will be better if you send code from your programe because this example have a problem
thisRow = datasetname[,]tablename.NewRow()
best regards
Yaroslav58211
Hi Shak and thanks for your efforts so far.
(1) The $ thing is an automatic "datatyping as string thingo" from the old days. It is also apparently current - see Wrox Programmer's Reference p132. I remember it from many years ago when I was using an old Commodore 5K machine. Instead of saying "Dim varname as string = "abcd"", can just say varname$ = "abcd"".
(2) I was horrified to see what I sent u. It myst have been literally finger trouble on my part as my code had the same sort of code as we have used before successfully. I Think my finger slipped on the keyboard and broke the line in half or something. Let's forget that.
(3) I have built a very simple testbed; an external MS Access database named MYTEST.MDB which has a single table named "Cat" with a single field/column named "Mouse". I opened a new project and moved a button to the form and double-clicked the button to get the event code up. I then went through the motions of building the connection string with the wizard and have a physical DB named MTTEST.MDB with table "Cat" and column mouse. I then used :Add New Data Source" and now the Data Sources window shows the logical MYTEST/Cat/Mouse configuration. All seemed ok to this point.
(4) I typed the following into the button click event handler:
Dim thisrow as DataRow ' ok so far
thisrow=MYTEST. ' intellisence offers 8 options, being "catDataTable";"catRow";catRowChangeEvent";"catRowChangeEventHandler"
it should have suggested "cat". the "catRow" option it offered was highlighted as [class cat row]
I played with all of them and none would remove the fatal error message: Reference to a non-shared member requires an object reference. In the following full code sample, both occurrences of MYtest.cat are underlined with blue squiggle with the same mentioned fatal error. I have underlined to duplicate the squiggle for u. This really has me stumped! Hey have just done lots more testing of deleting the datasource and recreating it using all variations of naming including ensuring the physical database was refreshed and still get the same errors @#$%^&*(. It seems as though thVB2005 cannot recognize what sort of object "cat" is although it is indented without an icon. and of course mouse is indented from cat!
Public
Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim thisrow As DataRowthisrow = MYTEST.cat.newrow()
thisrow(
"mouse") = "mickey"MYTEST.cat.Rows.add(thisrow)
End SubEnd
ClassRoMoVi
hi,Allen
intellisense actualy see 2 datasets 1 that in yoru solution explorer and the instance in in your form one as a class and other as object its tricky if you have both of them have hte same name, you can see that if you select the instance in your form and go to property and change its name , you can use a typed row from your class
like for example
dim datarow as mydatasetclassName.mytablerow
datarow = mydatasetinstanceName.MytableName.MytableNameNewRow
like that you will find even the intellisense will provide you with the columns names you don't have to type them like
datarow.mouse = "micky"
then add the row
MyDatasetInstanceName.MytableName.AddMytableNameRow(datarow)
if you have a listbox or something bound to bindingsource you will find the changes have been added to your form
hope this helps