Last post Mar 20, 2013 09:44 AM by mm10
Mar 13, 2013 09:02 AM|banksidepoet|LINK
I have a database with two columns (let's say A and B).
I have a Search Box in my site let's call it searchTB).
Basically I need help with THIS scanario (pseudo code)...
if the text entered into in searchTB is present in column A
Do procedure X (don't worry about this bit, I know what I'm doing here)
Do procedure Y (again, I know what goes here)
So, basically, I need the C# to take "searchTB.Text" and compare it against each value in "columnA" then perform an IF based on whether it is or not.
Best way to do this?
I am used to using C# to connect to a database so am fine with this part but what do I need to do... datareader? And if so, some help with the code for the reader would be great.
Mar 13, 2013 09:08 AM|MetalAsp.Net|LINK
Datareader sounds reasonable. Simply execute your sql select and check the reader's HasRows property to determine whether a match was found.
Mar 20, 2013 09:44 AM|mm10|LINK
You can implement the click event handler of the button as below:
bool isPresent = false;
using (SqlConnection conn = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=YourDB;Integrated Security=SSPI"))
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT A, B FROM Table";
cmd.Connection = conn;
SqlDataReader reader = cmd.ExecuteReader();
isPresent = true;
//Do procedure X
//Do procedure Y