954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to convert strSQLStmt result to integer?

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:

[code]
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 & "', '" & _
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
[inlinecode]


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

Adventurgurl
Newbie Poster
1 post since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

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.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You