Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to print Access Autonumber on a datagridview column

Posted on 2012-04-02
10
693 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

789 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