Insert with autonumeric

Bizkaitarra

Member
Joined
Feb 8, 2007
Messages
6
Programming Experience
1-3
Hi

I am trying to inset into a table a new row. This table has an autonumeric access primary key.
The problem is that when I trie to make an insertion into it I don´t know how to make that the autonumeric key generate automatic. I can only insert new rows by writing the number I want in this field....

Here is some code if you want to see it:

Me.GAPIDataSource.InsertCommand = "INSERT INTO [Especialidad] ([idEspecialidad], [nombre], [totalCreditos]) VALUES (@idEspecialidad, @nombre, @totalcreditos)"
Me.GAPIDataSource.InsertParameters(0).DefaultValue = Me.idTemporalLV.Text 'I want to make this autonumeric, not have to write manually
Me.GAPIDataSource.InsertParameters(1).DefaultValue = Me.NombreTB.Text
Me.GAPIDataSource.InsertParameters(2).DefaultValue = Me.TotalCreditosTB.Text
Me.GAPIDataSource.Insert()
 
Don't include the autonumeric field in the insert command:

VB.NET:
INSERT INTO Especialidad (Nombre, totalCreditos) VALUES (@Nombre, @totalCreditos)

-tg
 
Thanks

I have tried to do that but.... I have an other error message:

VB.NET:
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GAPIDataSource.InsertCommand = [/SIZE][SIZE=2][COLOR=#800000]"INSERT INTO Especialidad (Nombre, totalCreditos) VALUES (@Nombre, @totalCreditos)"[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Me.GAPIDataSource.InsertParameters(0).DefaultValue = Me.idTemporalLV.Text 'I want to make this autonumeric, not have to write manually[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GAPIDataSource.InsertParameters(0).DefaultValue = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].NombreTB.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GAPIDataSource.InsertParameters(1).DefaultValue = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TotalCreditosTB.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GAPIDataSource.Insert()[/SIZE]
The error:
Input string was not in a correct format.
 
Back
Top