Hello all ^_^
Some kind of noob question, but...
I'm using : Microsoft Visual Studio Express Web Developpement and a local MS Access database (TJA.mdb).
I'm trying to create a simple web page with a FormView. When I validate an insert command the page crash because the primary key of my table is not populated. This is a "Autonumberd" field called "ID". Ok since the FormView does not handle the the AutoNumberd field automaticaly, I've added some code to call a SQL query which returns a single value (scalar query). This query is not a stored procedure. Here is the code I use :
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInsertingIf e.Values("ID").ToString = String.Empty ThenEnd SubDim Conn As New AccessDataSource("App_Data\TJA.mdb", "SELECT MAX(ID)+1 AS ID FROM Team") [What else ] e.Values("ID") = [Something from Conn...]End If
But errrrr.. I'm kinda lost. Since "SqlDataReader","SqlDataAdapter" disapears from VS 2005, what am I suppose to do here
Thanks a lot for you helps
^_^'

Simple isn't it ? Returning a scalar data value...
Alex_Mann
Thx shakalama for your're anwser.
You're right, in fact when creating the "INSERT" command I forgot to remove the primary key from the SQL. ie : "INSERT INTO MyTable (ID, Name) VALUES ( , )" (the wizards automaticaly adds each field), I had to remove my autonumbered fields : "INSERT INTO MyTable (Name) VALUES ( )", with this the DBMS (here Access) handle the autonumbered field. Otherwise I get a "trying to assign a null value to a not variant field".
Thx a lot.
Thread fixed ^_^
dcd112778
hi,
first of all you can make a field a primary key in your table and add make it auto generate the id itself like this
'creating table Dim Tb As New DataTable("Table1")Tb.Columns.Add(
"id", GetType(Integer))Tb.Columns.Add(
"name", GetType(String))Tb.Columns(
"id").Unique = TrueTb.PrimaryKey =
New DataColumn() {Tb.Columns("id")} With Tb.Columns("id").AutoIncrement =
True.AutoIncrementSeed = 1
End WithSecond if your Msaccess table auto generate the id by itself you simply use SQLStr = "Insert into mytble(........." without adding the id value it will be genereated in access table even you don't have to use executescalar
hope it helps
RayHerring
Hi, SuperPoney
you are welcome
Best Regards