using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
private static string strConnect = "Data Source=.//SQLEXPRESS;database=test;UID=sa;PWD=sa;";
private SqlConnection conn = new SqlConnection(strConnect);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
conn.Open();
string sql = string.Format("SELECT * FROM MANLIAN WHERE 姓名='{0}'or 电话='{0}' or 电子邮件='{0}'", textBox1.Text);
SqlCommand jingzhun = new SqlCommand(sql, conn);
SqlDataReader reader = jingzhun.ExecuteReader();
while (reader.Read())
{
string[] str = new string[3];
str[0] = reader[0].ToString();
str[1] = reader[1].ToString();
str[2] = reader[2].ToString();
ListViewItem li = new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text = str[0];
li.SubItems.Add(str[1]);
li.SubItems.Add(str[2]);
LV.Items.Add(li);
reader.Close();
conn.Close();
} MessageBox.Show("没有你要的东西");
}
else if (radioButton2.Checked)
{
conn.Open();
string a = "%" + textBox1.Text + "%";
string sql = string.Format("SELECT * FROM MANLIAN WHERE 姓名 like '{0}' or 电话 like '{0}' or 电子邮件 like '{0}'", a);
SqlCommand mohu = new SqlCommand(sql, conn);
SqlDataReader reader = mohu.ExecuteReader();
while (reader.Read())
{
string[] str = new string[3];
str[0] = reader[0].ToString();
str[1] = reader[1].ToString();
str[2] = reader[2].ToString();
ListViewItem li = new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text = str[0];
li.SubItems.Add(str[1]);
li.SubItems.Add(str[2]);
LV.Items.Add(li);
reader.Close();
conn.Close();
}MessageBox.Show("没有你要的东西!");
}
else
{
MessageBox.Show("请选择查询方式!");
}
}
}
}
个人网站 www.perise.cn 欢迎光临~~~