Hi WomanPro, Thank you very much for your help.
I shall certainly look up these things and I appreciate your recommendations. I note that I must use the executeNonQuery method to update etc. thanks.
I feel you may misunderstand my background though. I certainly do not ask questions here because I am lazy- I hope you don't think that.
I decided to change career back in 1998 and went to college part time while still working full time and paying my mortgage. It took until 2002 to reach the cooperative program and 2 years to complete my cooperative project working all hours except during the day (analysis and design of complete database and software system for a local area government department- they have been using the system for some years now). By then the colleges were allowed to offer diploma programmes so I upgraded and went full time for another year to get my diploma, as I was by then unemployed.
My SQL class was taught by an experienced database administrator working for the government and I did very well at it. My VB6 system, SQL queries & stored procedures included, has worked well all this time.
I now have become unemployed and need to learn the new versions of languages because all job posts want .Net.
The main problem is learning VB.net, which is very different and MS has changed everything from the way VB6 worked.
I chose a smaller application that I wrote a few years ago as an exercise to learn VB.Net. I tried the conversion wizard but that produced so many unresolved errors that I gave up after some time and began writing the application from scratch in VB.net, learning as I go.
Just about everything that works in the VB6 version does not work in VB.Net (I'm using VS2008).
The sql expressions still work fine in the VB6 program but the VB.Net program is still not there yet- it has been throwing up errors in the IDE during runtime. At least I have the main form of the program running and loading all the data so far.
Just so you know, I have actually spent a LOT of time searching on Google to solve these problems before resorting to Tek Tips. I spend all day and all week working on this, aiming to understand it as much as I do VB6 and C++ so I can apply for a job. I am exhausted at the end of each day.
Unfortunately Internet searches can be hit or miss (no pun intended) and unless you use exactly the right search words you can miss by a mile. I have also found search results on MSDN help less helpful than the help provided on forums.
Anyway, once again, I really appreciate all help offered here and I will definitely follow up on your recommendations and keep trying until I get this to work and get another job.
Thank you.
Regarding the primary key. Yes, that's a very basic requirement of database design that I learned years ago.
My database for this application is a small Access database, to keep the program portable; I could set the client to connect to a shared database on the company network or to a local copy when I travelled away from the office and country.
The table in question does have a primary key and I use that in the sql statement to refresh the current row or field I am working on. However, whereas in Vb6 the
recordset.Resync adAffectCurrent method correctly refreshes the recordset and grid, in VB.Net a new (duplicate) row appears in the grid when I do the
.fill with a sql string that specifies the primary key of this record:
"SELECT * FROM Fields WHERE FieldID=" & gbindSourceFields.Current("FieldID").ToString
I tried with and without the .ToString and both ways produce the same string variable, so when I hover over this string variable in my debugging, it displays "SELECT * FROM Fields WHERE FieldID=2"
This same type of expression works for me in stored procedures and although the primary key above is produced from accessing a bindsource column value, the string variable still shows it looks correct.
I had also tried with the extra single quotes around the appended primary key as you saw in my earlier post, just in case the bind-source value was not being supplied in the way I expected, but naturally that raised an error.
The whole set of lines from this section is:
Code:
Dim pstrSQL As String = "SELECT * FROM Fields WHERE FieldID=" & gbindSourceFields.Current("FieldID")
gdatAdaptFields = New OleDb.OleDbDataAdapter(pstrSQL, gconDBConnection)
'// resync current record with database value in case it changed after I first loaded the client
gdatAdaptFields.Fill(gdtFields)
AHA.. This very minute, while writing this and testing, I think I have it working but I don't know why my statement above causes that problem.
I just tried selecting the
single column that I want to refresh:
"SELECT NoteField FROM Fields WHERE FieldID=" & gbindSourceFields.Current("FieldID")
... instead of all fields (
SELECT *) and the form opened with NO extra duplicate row!
That will work for me so I will press on and try to get changes updated to the database. Phew.
I wonder why SELECT * produces a duplicate row, even though I am using a WHERE clause with the primary key??
I don't like loose ends so it would be nice to resolve the reason for this.
I hope others may benefit from this finding.
Many thanks again for all help offered.