dataAdapter fill/update prob

omart

Member
Joined
Jul 6, 2008
Messages
13
Programming Experience
1-3
I am using vb .net 2003, and ms access, using oledb connection and creating a class library.

my query is to get the data, sorted. I have a basic sql statement that uses order by...

if i add a record, then
the new record comes at the bottom. even if i update first, before i display

if the access database is changed, out side my vb program, then
the changes dont show up.

If i try to fill the 'da' again, before i display, then
i get double the records.

if i stop my program after each operation i am testing then
it seems to work fine.


And for now im just adding the items in a list box, using a for each loop.

how do i either:

a) Clear the dataadapter, and re-do the sql statement and get the data sorted properly.

b) perform a second sql query to get the sorted data, and fill the dataadapter properly.

Thanks
 
if i add a record, then
the new record comes at the bottom. even if i update first, before i display
New records always go at the bottom

if the access database is changed, out side my vb program, then
the changes dont show up.
Indeed. Did you expect them to? Why?

If i try to fill the 'da' again, before i display, then
i get double the records.
Indeed. The da downlaods all matching records and puts them in the nominated table. If you fail to clear the table first, then you will end up with repeated rows.

if i stop my program after each operation i am testing then
it seems to work fine.
I dont understand your problem? Try reading the DNU link in my signature and see if it assists your understanding

And for now im just adding the items in a list box, using a for each loop.
Databinding can do that for you

a) Clear the dataadapter, and re-do the sql statement and get the data sorted properly.
You dont clear a dataadapter because a dataadapter is a device that transports data to and from a database. It has no data storage capabilities of its own

b) perform a second sql query to get the sorted data, and fill the dataadapter properly.
If your select statement contains an order by clause the data will be sorted. Ref clearing a dataadapter, see above

youre welcome
 
Thanks for the replies guys.

My code got to be out of hand its pretty all over the place right now I was trying different things.

But here is the purpose of my progrm:
It’s an add-in that will be used from a couple different apps

the goal is to increment the table by one, but first it has to check if any previous values/rows are missing, (I am comparing the current row with the next row to see if there is a gap, that’s why I always need the data sorted and up to date)
((That’s the only way I see of doing it right now, is there a sql function that will do this type of check??))

If there is a gap in the table then, re-use the missing number

When the user presses a button it calls my function to connect to the database then:
-get all the data sorted
--is there a gap
---yes -> use the missing number
---no -> increment the table by one

At this point I am only testing in a very basic vb app that I created:

My test app, I made reference to my dll and created an object and I can see all the functions I made; that’s all working fine.

I solved one of my issues, while copy and pasting my code..

In my test app I made a connection to the database on form load with:
VB.NET:
        mc = New dbt.mapicsPop
        mc.conn("C:\db1.mdb")

in the test app one button displays the data in the listbox(thanks for the tip on databinding)

the other button would call a function that would do the check, then add a row to the table.

I took the connection part from the form load, and put it in the button to display the data, at the top.
now whenever I press that display button, it will display the data up to date and sorted properly. Because I guess it creates a new connection object, runs the sql string, and fills the ds again.

So my problem is, I only know how to run a sql query as part of the connection string.
VB.NET:
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & dbLoc
            con.Open()
            'MsgBox("A Connection to the Database is now open")

            sql = "SELECT * FROM mapics order by mapicsNum" 
            da = New OleDb.OleDbDataAdapter(sql, con)

            da.Fill(ds, "mapic")

How can I just run a query, without reconnecting to the database, and get the sorted data (or maybe just run a completely different query), without using those 6 lines of code?
Or do I just clear the ds first, then re-fill it?

Because right now with my temporary fix, the program will only work preoperly if I hit the button to display first, example:

Press the button to display…good.( makes the connectioin to the db)
Press the button to add record…good(I can press this button all day works).

If I manually delete a record in the db and press the button to add record then
Works the first time but puts it at the bottom, (I understand this is normal now)

If I hit the button to add record again then
I get an error because this ds is not sorted yet, and my program checks current record and next record to see if there is a gap. In this case it thinks there is a gap but the missing value is at the bottom of the table, so I get an error when trying to add a new record with the same value)

If I hit the button to display, before I hit the button to add a record the second time then
It will work normally, because it goes through that whole connection process, and gets the sorted data.


Thanks again, sorry for all the typing:(
 
its a job numbering system, the number will be associated with a drawing file. i only have a range of numbers to work with, everytime the user runs my program they get a job number.

but just in case some one makes a mistake and assigns a job number to something that does not need a number, or if for some other reason the job number needs to gets freed up for use.

i dont want to keep just generating new numbers if previous numbers can be used.
 
if you have only a limited number of jobs available I suggest you prepoulate your table with all available job numbers, then every time you wish to use one, you should:

SELECT MIN(job_num) FROM table WHERE some_other_field IS NULL
 
ic, I was thinking on doing something like that but i was thinking on speed issue, which i dont really think is that much of a problem but the number range is from 95000009 - 9999999. do you think this would impact your sugestion att all??

thanks
 
Just shy of 5 million possible job numbers and youre concerned about making sure you dont miss any?

Why?!
 
I was just thinking of all the things that could go wrong, and just assumed that if there is a gap, or unused numbers, it would be a problem.
But i am not gunna pre populate the table, first i am gunna use your sql statement to see if there is a job number that has no description(this will happen if some one assigns one, then for some reason they decide they didnt need one). if there is none then i will just add a record.

Thanks again for your input
 
Last edited:

Latest posts

Back
Top