get value fro a table

J

JFB

Hi All,
I have a table Persons(id,customerid,name,lastname,addres....)
When I insert a row to this table a triggers fired on sql and get customerID
from customer table and update the customerID column.
I have an input form in vb.net to set the new values for Persons table and
Houses table.
The problems is that at the time that I insert a row to the Persons table I
wan to retrieve the customerID and use this Id to store the new row in
Houses table with the data in the vb form.
How can I do this?
customerID is not primary key on Persons table.
Tks in advance
JFB

Here is the way that I'm inserting the row in Perons table
'Insert Values to the Persons table

'Create sql command

Dim conn As New SqlConnection(connectionString)

Dim insertSQL As String = "INSERT INTO
Persons(lastName,firstName,phone,cellular,email,status) values
(@lastName,@firstName,@phone,@cellular,@email,@status)"

Dim cmd As New SqlCommand(insertSQL, conn)

'Add the input parameters

Dim Param As SqlParameter = cmd.Parameters.Add("@lastName",
SqlDbType.VarChar, 100)

Param.Value = ValidText1.Text

Param = cmd.Parameters.Add("@firstName", SqlDbType.VarChar, 100)

Param.Value = ValidText2.Text

Param = cmd.Parameters.Add("@phone", SqlDbType.VarChar, 50)

Param.Value = ValidText3.Text

Param = cmd.Parameters.Add("@cellular", SqlDbType.VarChar, 50)

Param.Value = ValidText4.Text

Param = cmd.Parameters.Add("@email", SqlDbType.VarChar, 50)

Param.Value = ValidText5.Text

Param = cmd.Parameters.Add("@status", SqlDbType.Bit, 1)

Param.Value = 1

Try

'Execute command

conn.Open()

Dim rows As Integer = cmd.ExecuteNonQuery

Catch ex As Exception

MsgBox(ex.ToString)

Return

Finally

conn.Close()

End Try
 
W

William Ryan

Would a Return Value or Output parameter work for you? Perhaps in the
Stored Proc you are calling, you could retrieve the value you are looking
for, and either return it as Output Param or Return Value. If you go over
to www.betav.com , check out Bill's article under Articles, MDSN, Retrieving
the Gozoutas --- it should get you through this.

HTH,

Bill
 
J

JFB

Tks for reply...
I saw the example but this is for retrieve values from a table...
I want to retrieve a value at the same time when I'm doing the insert, can I
do this?
Do you have any sample code?
Regards
JFB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top