日期:2014-05-17 浏览次数:20860 次
string strConnection = "Trusted_Connection=SSPI;Data Source=localhost;Initial Catalog=yourdb;Connect Timeout=30";
private void QueryUserInfo()
{
this.dataSet1.userinfo.Clear();
using (SqlConnection conn = new SqlConnection(strConnection))
{
conn.Open();
//可根据CheckBox动态拼SQL
string sql = string.Format("select * from userinfo where A = '{0}'", "IDABC");
SqlCommand command = new SqlCommand(sql, conn);
SqlDataReader reader = command.ExecuteReader();
this.dataSet1.userinfo.Load(reader);
reader.Close();
command.Dispose();
}
this.dataSet1.userinfo.AcceptChanges();
//TODO显示到页面上,Grid或者其他控件
}
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 SqlTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strSql = "";
string NameList = "";
List<string> list = new List<string>();
foreach (CheckBox item in groupBox1.Controls)