VB.Net : Inserting data in MS Access database

Rahul++

SuperUser
Skilled
Hello,

I am completely beginner in VB.Net and have to work on some project..

I have 'Customer' table in database 'hotelData' with following fields

CustomerID - (Primary, Number)

FirstName

LastName

Address

PhNo

MobileNo

After watching some video tutorials provided by Microsoft. I created a Windows Form and dragged Data Source (Customer) into it, it created TableAdapter. When I ran the project, it was fetching values from Customer table. I added one record and clicked on Save but it gave me one exception :

"CustomerID does not allow Null"

When I removed Primary Key from CustomerID and tried to save the data. Exception didn't occurred but the it failed to update database.

Can anyone help me out?
 
#[member='CA50'] - Yes, CustomerID is primary key. I get "CustomerID does not allow Null Value" exception whenever I try to insert a record into database. How can I make sure that CustomerID isn't null? Actually, I want CustomerID to be auto incremented. I tried putting CustomerID primary as well as Auto Number (increment) in database but database isn't getting updated
<
 
#[member='Rahul++'], while creating the DB, you will have to un-check the "Allow NULL" field.

Next for the auto-increment, i suggest you to write a separate code for it. For 1st one read the current no of rows in the DB, and save it in the customer ID field, for the rest, read the previous customer ID, and increment it by 1
 
Fixed it.

Here's what I did,

- Set CustomerID field as Autonumber in Access database

- Opened Dataset in Dataset Designer in VIsual Studio

- Located Customer Table, selected CustomerID's properties

- In properties, "Allow DB Null" - True

"Auto Increment" - True

"Auto Increment Seed" - -1

"Auto Increment Step" - +1

"Unique" - True (Maintains primary key property)

Working flawlessly now

Thanks #[member='CA50'], #[member='Pat'] for taking a look
happy19.gif
 
Back
Top