R
ryan.mclean
Hi all, I am new to using sql server and parameterized sql. I am
hoping to be returned the value of a column that has been inserted.
Here is my statement
strSqlInsetrtTrack = _
"INSERT INTO TRACK (CASE_NUM, CERT_NUM, CLMT_NUM, BROKER_NAME, " + _
"CONTRACT_SEQ, TRACK_COMMENTS, DATE_OVER_SPEC, LAST_TOUCHED) " + _
"VALUES ('" + strCase + "','" + strCert + "'," + _
"'" + strClmt + "',@BrokerName,'" + strContractSeq +
"',@TrackComments," + _
"'" + txtDateOverSpec.Text + "',GETDATE()) " + _
"SET @TrackId = TRACK_ID"
Then I assign the parameters and I thought I could obtain the TRACK_ID
from the newly inserted row, which is an auto-enumerated field.
Anyway, here are the parameters:
With comInsertTrack
.Parameters.Add("@BrokerName", SqlDbType.Char, 50)
.Parameters.Add("@TrackComments", SqlDbType.VarChar, 500)
.Parameters("@BrokerName").Value = txtBrokerName.Text
.Parameters("@TrackComments").Value = txtTrackComments.Text
.Parameters.Add("@TrackId", SqlDbType.Int)
.Parameters("@TrackId").Direction = ParameterDirection.ReturnValue
.ExecuteNonQuery()
strTrackid = CType(.Parameters("@TrackId").Value, String)
End With
I'm not even sure this is waht was intended by the returnvalue
enumerator . . . it would be really cool if it would work
The errror is:
SqlException: Must declare the variable '@TrackId'
On the .ExecuteNonQuery() line.
Thank you for any assistance. Have a great day!
Ryan
hoping to be returned the value of a column that has been inserted.
Here is my statement
strSqlInsetrtTrack = _
"INSERT INTO TRACK (CASE_NUM, CERT_NUM, CLMT_NUM, BROKER_NAME, " + _
"CONTRACT_SEQ, TRACK_COMMENTS, DATE_OVER_SPEC, LAST_TOUCHED) " + _
"VALUES ('" + strCase + "','" + strCert + "'," + _
"'" + strClmt + "',@BrokerName,'" + strContractSeq +
"',@TrackComments," + _
"'" + txtDateOverSpec.Text + "',GETDATE()) " + _
"SET @TrackId = TRACK_ID"
Then I assign the parameters and I thought I could obtain the TRACK_ID
from the newly inserted row, which is an auto-enumerated field.
Anyway, here are the parameters:
With comInsertTrack
.Parameters.Add("@BrokerName", SqlDbType.Char, 50)
.Parameters.Add("@TrackComments", SqlDbType.VarChar, 500)
.Parameters("@BrokerName").Value = txtBrokerName.Text
.Parameters("@TrackComments").Value = txtTrackComments.Text
.Parameters.Add("@TrackId", SqlDbType.Int)
.Parameters("@TrackId").Direction = ParameterDirection.ReturnValue
.ExecuteNonQuery()
strTrackid = CType(.Parameters("@TrackId").Value, String)
End With
I'm not even sure this is waht was intended by the returnvalue
enumerator . . . it would be really cool if it would work
The errror is:
SqlException: Must declare the variable '@TrackId'
On the .ExecuteNonQuery() line.
Thank you for any assistance. Have a great day!
Ryan