Solved

How to print Access Autonumber on a datagridview column

Posted on 2012-04-02
10
687 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

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)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

15 Experts available now in Live!

Get 1:1 Help Now