【发布时间】:2016-06-02 01:57:57
【问题描述】:
我正在使用包含名称公司和国家/地区的组合框,因此用户可以从中选择以指定他想在文本框中搜索哪种形式,并且我需要以不同的形式查看我的搜索结果 (results.cs) 和我的搜索引擎在 (main.cs) 我该怎么做?
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
if (comboBox1.Text == "Name")
{
String var;
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Seif-\Documents\Visual Studio 2013\Projects\BusinessCard\BusinessCard\BusinessCards.mdf;Integrated Security=True");
SqlCommand sc = new SqlCommand("SELECT Name, Post, Company, Country, Email, Mobile, Tel1, Tel2, Fax, Address FROM BC where Name LIKE '" + textBox1.Text + "'", conn);
SqlDataAdapter sda = new SqlDataAdapter(sc);
DataTable dt = new DataTable();
sda.Fill(dt);
var = (string)sc.ExecuteScalar();
Search f2 = new Search();
f2.Show();
}
else if (comboBox1.Text == "Company")
{
String var;
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Seif-\Documents\Visual Studio 2013\Projects\BusinessCard\BusinessCard\BusinessCards.mdf;Integrated Security=True");
SqlCommand sc = new SqlCommand("SELECT Name, Post, Company, Country, Email, Mobile, Tel1, Tel2, Fax, Address FROM BC where Company LIKE '" + textBox1.Text + "'", conn);
SqlDataAdapter sda = new SqlDataAdapter(sc);
DataTable dt = new DataTable();
sda.Fill(dt);
var = (string)sc.ExecuteScalar();
Search f2 = new Search();
f2.Show();
}
else if (comboBox1.Text == "Country")
{
String var;
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Seif-\Documents\Visual Studio 2013\Projects\BusinessCard\BusinessCard\BusinessCards.mdf;Integrated Security=True");
SqlCommand sc = new SqlCommand("SELECT Name, Post, Company, Country, Email, Mobile, Tel1, Tel2, Fax, Address FROM BC where Country LIKE '" + textBox1.Text + "'", conn);
SqlDataAdapter sda = new SqlDataAdapter(sc);
DataTable dt = new DataTable();
sda.Fill(dt);
var = (string)sc.ExecuteScalar();
Search f2 = new Search();
f2.Show();
}
}
【问题讨论】:
-
重新格式化代码以提高可读性