i have some textbox to give input to store in the database it will work when i click save option.
my question is how to check the inputs are already exist
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 25, 2015, 11:29 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 25, 2015, 11:40 PM EDT
Before saving data into database you may check whether this value already exist in database or not
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Employee where name ='jignesh' ", Connection);
int Records = int.Parse(cmd.ExecuteScalar().ToString());
if(Records >0)
{
//Record already Exist
}
else
{
// insert data...
}
hope this will help you.
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 26, 2015, 12:00 AM EDT
con.Open();
string str = "select count(*) from pankaj where take='"+textBox2.Text+"'";
SqlCommand com = new SqlCommand(str, con);
int Num;
Num= int.Parse( com.ExecuteScalar().ToString());
if (Num > 0)
MessageBox.Show("Data is already exist");
else
{
// Here you can perform your Operation
}
com.ExecuteNonQuery();
con.Close();
Durga VelusamyRank #4,868 · 321 reputationPosted Mar 26, 2015, 1:50 AM EDT
example:
i have 4 number of combobox just i want to check 2nd combobox only whether it is already exist or not.
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 26, 2015, 2:10 AM EDT
string str = "select count(Field_Name) from Table-Name where Field_Name='"+ComboBox2.Selectedvalue+"'";
if this is not according per you requirement then please elaborate your query..............