Solved

How to print Access Autonumber on a datagridview column

Posted on 2012-04-02
10
697 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
[X]
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
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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