Dear sir,
I am inserting data through gridview. and again click on submit button with same data it display inserted successfully.
I want to display error message record already existed. Please help me and send code.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dorababu MekaPosted Dec 28, 2012, 7:02 AM
create a stroed procedure as follows
createPROCEDURE insertData
(
@ID int,
@Name varchar(50),
@Address varchar(50)
)
as
begin
iF NOT EXISTS (
select * from Employee
where EmployeeName = @Name AND Address = @Address) // here compare with your desired column
insert into Employee(EmpID,EmployeeName,Address)values(@ID,@Name,@Address)
END
from your code
string constring = ConfigurationManager.ConnectionStrings["vendorConn"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("insertData",sqlCon);
cmd.Parameters.AddWithValue("@ID", 2000);
cmd.Parameters.AddWithValue("@Name", "Dorababu");
cmd.Parameters.AddWithValue("@Address", "Hyderabad");
cmd.CommandType = CommandType.StoredProcedure;
sqlCon.Open();
if (cmd.ExecuteNonQuery() > 0)
murali athmuriPosted Dec 28, 2012, 5:46 AM
I am sending by designing page.
Dorababu MekaPosted Dec 28, 2012, 5:16 AM
murali athmuriPosted Dec 28, 2012, 4:29 AM
Dorababu MekaPosted Dec 28, 2012, 3:37 AM