majhl
09-11-2008, 06:12 AM
Hello All,
I need to check data before an insert for obvious reasons!
I've set up a stored procedure in my db which is the following:
Create Procedure SPChkRefno
@refno nvarchar(5)
AS
SELECT count(refno)
AS RefCount
FROM tblscreening
WHERE refno = @refno
I have then written the following code in my .net page:
Dim strConn As New SqlConnection
Dim comm As SqlCommand
Dim paramRefNo As SqlParameter
strConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
comm = New SqlCommand("SPCheckDRefNo", strConn)
comm.CommandType = CommandType.StoredProcedure
paramRefNo = New SqlParameter("@refno", SqlDbType.NVarChar,5)
paramRefNo.Value = txtRefNo.Text
comm.Parameters.Add(paramRefNo)
strConn.Open()
comm.ExecuteScalar()
If Not (txtRefNo.Text = String.Empty) Then
If Then
???What goes here???
End If
End if
I'm puzzled as to how to complete the code, i.e. how to find out the result of the query and act accordingly. Can someone help out?
Thanks very much.
I need to check data before an insert for obvious reasons!
I've set up a stored procedure in my db which is the following:
Create Procedure SPChkRefno
@refno nvarchar(5)
AS
SELECT count(refno)
AS RefCount
FROM tblscreening
WHERE refno = @refno
I have then written the following code in my .net page:
Dim strConn As New SqlConnection
Dim comm As SqlCommand
Dim paramRefNo As SqlParameter
strConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
comm = New SqlCommand("SPCheckDRefNo", strConn)
comm.CommandType = CommandType.StoredProcedure
paramRefNo = New SqlParameter("@refno", SqlDbType.NVarChar,5)
paramRefNo.Value = txtRefNo.Text
comm.Parameters.Add(paramRefNo)
strConn.Open()
comm.ExecuteScalar()
If Not (txtRefNo.Text = String.Empty) Then
If Then
???What goes here???
End If
End if
I'm puzzled as to how to complete the code, i.e. how to find out the result of the query and act accordingly. Can someone help out?
Thanks very much.