I am using the following code to insert a record into a table. I need to be able to check to see if the value in txtFilename already exists, if it does display a message "Filename already used" otherwise go ahead and insert the record
Thanks
This is my SP
Thanks
Code:
Private Sub AddFile1()
Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("FileawaySQLConnectionString").ConnectionString
Dim con As New SqlConnection(ConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "AddFile"
cmd.Parameters.Add("@BoxID", SqlDbType.Int).Value = HiddenBoXID.Value.Trim()
cmd.Parameters.Add("@Filenumber", SqlDbType.VarChar).Value = txtFileName.Text.Trim()
cmd.Connection = con
Try
con.Open()
cmd.ExecuteScalar()
Catch ex As Exception
Throw ex
Finally
con.Close()
con.Dispose()
End Try
Session("Filename") = txtFileName.Text
lblBoxNumber.Text = "File name " + Session("Filename") + " has been added."
Me.pnlFilesAdded.Visible = True
Me.grdFilesAdded.Rebind()
End Sub
This is my SP
Code:
USE [Fileaway]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddFile]
(
@BoxID int,
@FileNumber varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.Files (BoxID, FileNumber)
VALUES (@BoxID, @FileNumber)
END