Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi this is small but i am new so please guide


i had one textbox which i will be saving its value in to the databse if it is not null on click of button but here is i need help the value which i am saving is if already exists in the databse table i should get a message on my screen record already exists...please suggest
Posted

try this code...

C#
qry = "select * from department_master where dep_code='" + txt_code_add.Text + "'";
               sql_cmd = new SqlCommand(qry, sql_con);
               sql_con.Open();
               sql_rs = sql_cmd.ExecuteReader();
               if (sql_rs.Read())
               {
                   //"*The code already existing,Please change your code";
               }
               else
               {
                   //Write insert query
               }


i hope this code helps you a bit..
 
Share this answer
 
You have to check first in table with if condition...:)

SQL
if(select * from users where name=@name <> '')
BEGIN
	INSER INTO......
END
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900