PDA

Click to See Complete Forum and Search --> : [RESOLVED] code error


d2005
Sep 28th, 2005, 07:55 AM
anyone see the trouble with this

im trying to assign a value taken from the primary key field and increment it by one to use in an insert

Dim z As Integer
Dim max As String = "select z = MAX(c_msg_nr) from tb_orig_msg"
Dim cmd1 As New SqlCommand(max, oSQLConn)
z += 1

mendhak
Sep 28th, 2005, 08:21 AM
anyone see the trouble with this

Yes. :)

You've declared z as an integer, then tried to assign it inside the sql query string. You need to look at ExecuteScalar.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataodbcodbccommandclassexecutescalartopic.asp

d2005
Sep 28th, 2005, 08:35 AM
resolved thanks mendhak
ive had some serious trouble with this
genious

my code if any ever has a similar problem

Dim z As Integer
Dim max As String = "select MAX(c_msg_nr)+1 as z from tb_orig_msg"
Dim cmd1 As New SqlCommand(max, oSQLConn)
cmd1.ExecuteNonQuery()
z = cmd1.ExecuteScalar().ToString()


thanks again

mendhak
Sep 28th, 2005, 09:24 AM
Btw, You don't need this line:

cmd1.ExecuteNonQuery()

Why did you include it?