Creating New User Issue in VB.net with SQL 2005:

I have a LogOn table and a Usr (User) table. A form that collects the new UserID,Password,FirstName,LastName, etc...

I want to have two separate INSERT statements to first insert the UserID & Password. Then grabs the LogOnSys just created and create a FK relationship for the next INSERT statement.

So I am looking for a statement to parse out the LogOnSys from strSqlSmt2:

strSqlStmt = "INSERT LogOn (UserID,Password)" & _
"VALUES ('" & pobjCreateTech.UsrName & "', '" & pobjCreateTech.Password & "')"

strSqlStmt2 = "SELECT LogOnSys FROM LogOn WHERE UserID = ' " & pobjCreateTech.UsrName & "')"

'Convert SQL Statement from string to integer?
'intLogOnSys = strSqlStmt2

strSqlStmt3 = "INSERT Tech (FstNam,LstNam,Title,Email,Phn,LogOnSys) " & _
"VALUES ('" & pobjCreateTech.FirstName & "', '"[/COLOR] & _
pobjCreateTech.LastName & "','" & pobjCreateTech.Title & _
"','" & pobjCreateTech.Email & "','" & pobjCreateTech.Phone & "','" & intLogOnSys & "')"


objSqlCmd = New SqlCommand 'instancating sqlCommand
objSqlCmd.Connection = objSqlConn
objSqlCmd.CommandText = strSqlStmt & strSqlStmt2 & strSqlStmt3
objSqlCmd.CommandType = CommandType.Text

Thanks for any help at all!!! and sorry for making the question so long, I just wanted to make sure people understood my question. :) Also, if there is a lot easier way of doing this... PLEASE tell me. :D

Check this out:

http://support.microsoft.com/kb/320141/EN-US/

Or consider SCOPE_IDENTITY() look it up in Books Online that comes with SQL Server, you can use it in a stored procedure to return the last Identity insert value from an insert statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.