您好,我的主页上有一个搜索框,其中包含一个文本框 (TextBox1.Text) 和一个按钮 (Button1_Click),这两个都是 asp 控件。
我试图弄清楚如何搜索我的数据库并检索可能相似的东西,我有一个用户表,我想搜索用户但拼写可能是错误的所以如果拼写是我如何仍然返回某人错了,如果你知道我的意思?
到目前为止:
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?
}
我想弄清楚的另一件事是如何将其发送到另一个页面以在 ListView 中查看。
最佳答案
关于c# - 通过文本框和按钮搜索 mysql 数据库并将输出重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5522627/