Solved

How to print Access Autonumber on a datagridview column

Posted on 2012-04-02
10
684 Views
Last Modified: 2012-04-02
In Access database, assuming that a table is created with three fields and the first field is set to autonumber.

Now on an Access database Datasheet view, when a user enters a value on a new record, automatically the autonumber is generated and displayed on the first cell of the current row while the user enters the data on the following cells.

But i am writing my application in vb.net for the user interface and will be using a datagridview.

In the girdview when the user starts entering data on the new row, is it possible to display the autonumber on the gridview cell (i.e. is the actual autonumber that access has or will generate)

I am using vb.net and access database.

Thanks in advance.
0
Comment
Question by:baabaa_nl
  • 6
  • 4
10 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37795733
Do you need to show the number? These number columns are usually hidden in a UI as these are usually not of any interest to the user.

See this example

http://www.c-sharpcorner.com/uploadfile/santowebster/how-to-add-an-autonumber-column-in-a-datagridview/
0
 

Author Comment

by:baabaa_nl
ID: 37795777
Hi CodeCruiser,

I believe that the code in the article you gave was generating its own autonumber on the gridview it self.

But i want the autonumber from the access database itself(i.e. suppose i was going to enter a new row in the access database datasheet view and it was generating a number 15, but since i am doing the same thing in gridview, is it possible to get that autonumber on my gridview's first column cell.).

Hope i was clear.

Thanks in advance.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37795836
Then you would have to handle the RowsAdded event and generate the number yourself. Is it a single user app?

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsadded.aspx
0
 

Author Comment

by:baabaa_nl
ID: 37795981
No,

I want the autonumber that was geneterated on the access database to be displayed on the datagridview of my applicatoin.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 37796075
>I want the autonumber that was geneterated on the access database to be displayed on the datagridview of my applicatoin.

That would happen AFTER you send the changes from the grid to the database using the DataAdapter.Update method. This wont happen when adding a new row in grid. You can achieve this by adding a button on form "Add Row" which inserts the empty row in Access and reloads the grid so it shows an empty row with ID generated.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:baabaa_nl
ID: 37796087
I hope you get the point i am trying to say because, when you enter a value on the new row, (assuming that the row's first column is set to autonumber, and when the data is enterd on the rest of the columns, the new autonumber immediately apperars on the column which was set with auto number.) so but in this case, i will not use my access database directly, instead the database will be on a different location and i will be using my vb.net application which will have a datagridview, which will have connected to the database. and when i start entering the data on the appropriate columns, the database will generate the autonumber, and i want that auto number to be displayed on the gridview.

I will also insert the image below for what i am trying to do.

PIc 1
pic 2
0
 

Author Comment

by:baabaa_nl
ID: 37796099
Hi Codecuriser,

so i be sending a black record to the database and reloading it would give me the id generated. its realy a good idea, but would it cause any problem in the sql if i a sending blank values at first for me to generate the autonumber and retrieve it back again?
0
 

Author Comment

by:baabaa_nl
ID: 37796196
CodeCruiser,

>>Is it a single user app?


This is not a single app, this will be used by 3 or 4 users at the same time.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 37796387
I would suggest you hide the autonumber column. You did not answer my question: Is this number important for the user?

Access and DataGridView are two different things. Access implements the feature for you but you would have to implement the feature for datagridview.
0
 

Author Comment

by:baabaa_nl
ID: 37797071
Hi codecruiser,

Honestly the autonumber is not need for the user, I was trying to see if it was possible to to get that functionality that access does(i.e. displaying the autonumber first when data is entered on the new row.)

Thank you CodeCruiser
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now