G Gr
G Gr

Reputation: 6090

search mysql database via textbox and button and redirect output to another page

Hi on my masterpage I have a search box contained in it is a textbox (TextBox1.Text) and a button (Button1_Click) both asp controls.

Im trying to figure out how to search my database and retrieve things that may be similar, I have a User table that I would like to search for Users but spelling could be wrong so how do I still return someone if the spelling is wrong if you know what I mean?

So far:

protected void Button1_Click(object sender, EventArgs e)
{
    // Search Users
    String Search = TextBox1.Text;
    using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=x; Password=x;"))
    {
    cn.Open();
    using (OdbcCommand cmd = new OdbcCommand("SELECT * FROM User WHERE FirstName LIKE '%"+ Search +"%';", cn))
    //not sure if this is correct, will it return anything that is similar to what is typed?       
    Response.Redirect("Search.aspx");
    // dont know how to send this to a listview on another page? 
}

}

The other thing im trying to figure out is how I would send that to another page to view in a listview.

Upvotes: 1

Views: 2849

Answers (1)

HABJAN
HABJAN

Reputation: 9338

Take a look at Soundex or Levenshtein distance.

Upvotes: 1

Related Questions