Solved

How to print Access Autonumber on a datagridview column

Posted on 2012-04-02
10
689 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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 different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

776 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