Hi,The sql stored procedure for insert is:if not exists (Select id, name from table_name where id=@id) INSERT INTO table_name id, name) Values (@id,@name)
I have a form into VB with a textbox and a insert ButtonAt the insert button i have the function for insert :Dim con As New SqlConnection("Server=; ..)con.Open()Dim cmd As SqlCommand = New SqlCommand()cmd.CommandType = Data.CommandType.StoredProcedurecmd.CommandText = "Stored_Procedure_Name"cmd.Connection = mConnectioncmd.Parameters.Add(New SqlParameter("@id", Data.SqlDbType.Int)cmd.Parameters.Add(New SqlParameter("@name", Data.SqlDbType.nchar)cmd.Parameters("@id").Value = txtID.Textcmd.Parameters("@name").Value = txtName.textcmd.ExecuteNonQuery()con.Close()return True
Insert function work's , and when I try to insert a value that exist into database nothing happens because of the code from stored procedure.But i want to make a check into add function:- first: select the "id" values from table- second: compare values if equal with value from the textbox and when are equal then msgbox error.Thank's