You mean,
INSERT INTO TABLE(ID,NAME) VALUES(SELECT @New_ID = isnull(Max(ID),0) + 1 FROM TABLE,'rafael rodri')
Am I right
Main Topics
Browse All TopicsHow can I create sql sentence insert without auto increment in my database. My Table on database is that:
ID
NAME
PHONE
How is going to be my sentence SQL for Insert, becouse i don´t know what is the last ID.
Insert Into TABLE(ID,NAME,PHONE) VALUES(xxxxxxxxxx,'RAFAEL'
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi
First of all i suggest you to use AutoIncrementField for ID
further,
Are u using SQL Server? and Do u use StoredProcedures? if your answer is YES
Write a strored procedure and call it from ur code behind
for ex:
Your Stored Procedure here
CREATE PROCEDURE dbo.InsertIntoTableName
AS
DECLARE @MaxId int
SELECT @MaxId = Max(ID)+ 1 FROM docmasters
Insert Into TABLE(ID,NAME,PHONE) VALUES(@MaxId,'RAFAEL',404
GO
.....
I assume u have a command button to save the data
Private sub btnSaven_Click(......)
Dim sqlConn As SqlConnection = New SqlConnection(YourDataBase
Dim sqlCmd As New SqlCommand
sqlCmd.CommandText = "InsertIntoTableName" ' Thisis your stored procedure name
sqlCmd.CommandType = CommandType.StoredProcedur
sqlCmd.Connection = sqlConn
Try
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
' return a message that the insert is failed
Finally
sqlConn.Close()
End Try
End Sub
HTH
Happy Programming
Rana
Business Accounts
Answer for Membership
by: sajuksPosted on 2006-02-20 at 19:40:46ID: 16005735
u mean the field id is not an autoincrement field...right ?
')
SELECT @New_ID = isnull(Max(ID),0) + 1 FROM TABLE
then u can use this value @NEW_ID to set the value in the table for ID.
if the field is an autoincrement field then u dont need to specify the ID field..u could've
Insert Into TABLE(NAME,PHONE) VALUES('RAFAEL',4047684850