ASP.net INSERTING To Access

Capodecina
Permabanned
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:


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 :mad:

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)
 
I'd really like to try stick to using the DAL method and keep all SQL code and so on seperate from presentation etc.

Plus i've got no idea what's going on there (I'm a noob).
 
Sorry, if you read my reply on your previous post.
I just looked up queries in Access and apparently you can't use SCOPE_IDENTITY() in the same query. :o

If you just want to insert a product remove the SCOPE_IDENTITY() bit, aswell as the ending ';' after the insert, it should keep the running order of any autonumbers.

I gave it a go, but like you said it will not work.

If you check my post again I still can't seem to INSERT any way I try :\

Cheers for trying to help people, much love <3
 
I hadn't checked the BLL tutorial because it was the next tutorial following from the first DAL one. I wasn't going to move on until I had got everything from the first one sussed.

I'll have a look at it now and let you know, cheers for the help :)
 
Ok well that looks complicated :\

Not totally understanding the point for this 'Business Layer'.

I should really try get SQL Server sorted (can't be bothered explaining why i'm not using it right now, I just can't - work related).
 
Can't download that ZIP from work but i'll be sure to give it a go when I get hope.

Thanks for being so helpful, it's appreciated :D
 
Back
Top Bottom