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
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