Suppose..

I have 3 columns in database : Name,Age,Birthday.
I have 3 textboxes and a button for adding new row with values from textboxes in the data table , gridview.
When I click the button for adding a new row with those information , I need to check if the value from textbox for "Name" already exists in the data table in the column "Name" if yes then the update is canceled and the user is asked to enter another value.

Query the Name row for the name in the textbox.

Select * Were Name = textbox1.text

Don't forget the single quotes around the value if it's a string type column (or similar types). So you'd need to produce a query string like

string QueryString = String.Format("SELECT * FROM TableName WHERE (Name = '{0}')", textBox1.Text);

Make sure you replace "TableName" with the proper name of the table. That will give you the query string you need to run. If it returns back matches, then you know it already exists in the database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.