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.
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.
Pankaj Kumar ChoudharyPosted Mar 26, 2015, 6:10 AM
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..............
Durga VelusamyPosted Mar 26, 2015, 5:50 AM
example:
i have 4 number of combobox just i want to check 2nd combobox only whether it is already exist or not.
Pankaj Kumar ChoudharyPosted Mar 26, 2015, 4:00 AM
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();
Jignesh TrivediPosted Mar 26, 2015, 3:40 AM
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.
Khargesh RajputPosted Mar 26, 2015, 3:29 AM