- Joined
- 31 Dec 2003
- Posts
- 5,172
- Location
- Barrow-In-Furness
I'm having a problem INSERTING into an Access database. I'm following the DAL tutorial from http://www.asp.net/learn/data-access/tutorial-01-vb.aspx and using the Northwind database. The error message i'm getting is:
Error 1 'Public Overridable Function InsertProduct() As Integer' has no parameters and its return type cannot be indexed. H:\Projects\ManHours\Beverages.aspx.vb 17 56 H:\Projects\ManHours\
And here's the code:
I am new to this and any help will be appreciated
I've tried inserting data using another method and still had no luck. Here's that post.
Error 1 'Public Overridable Function InsertProduct() As Integer' has no parameters and its return type cannot be indexed. H:\Projects\ManHours\Beverages.aspx.vb 17 56 H:\Projects\ManHours\
And here's the code:
Code:
INSERT INTO [Products]
([ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued])
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
SELECT SCOPE_IDENTITY()
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim productsAdapter As New NorthwindTableAdapters.ProductsTableAdapter()
Dim new_productID As Integer = Convert.ToInt32(productsAdapter.InsertProduct( _
"New Product", 1, 1, "12 tins per carton", 14.95, 10, 0, 10, False))
productsAdapter.Delete(new_productID)
I am new to this and any help will be appreciated

I've tried inserting data using another method and still had no luck. Here's that post.
Learning has slowed down greatly, I just can't seem to get a new field created using a DetailsView control.
I'm thinking the problem is because of the AutoNumber (ID) field in the table i'm trying to enter data into.
"You tried to assign the Null value to a variable that is not a Variant data type. "
This is the insert query:
Code:INSERT INTO [tbl_Data] ([project_code], [date], [monday], [tuesday], [wednesday], [friday], [thursday], [saturday], [sunday], [ID]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
When I click the New hyperlink on the DetailsView control it removed the ID field from view (which is ideal).
Also.... how can I autopopulate fields? For example, the ID field needs to increment in sync with the database, the date field should really autopopulate with todays current date when a new entry is being made. What if I want to make an entry for the next date today though?
Argghhhh trying to teach yourself from a book that is using SQL Express and you have to use Access is an absolute pain.
I'm probably not even being clear at all
Alternatively, if someone uses ASP.NET 2.0 and Visual Web Developer and doesn't mind helping me on MSN (don't worry I do try fix things myself first, let me know if I can add you)