日期:2014-05-17 浏览次数:20923 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace SqlTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
private void dataSet1BindingSource_CurrentChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
string connectionString = "Provider=SQLOLEDB.1;Data Source=xxxx;Persist Security Info=True;Password=xxxxxx;User ID=sa;Initial Catalog=EntitledGroups";
string commandString = "Select username, password from user";
OleDbDataAdapter DataAdapter = new OleDbDataAdapter(commandString, connectionString);
DataSet DataSet = new DataSet();
DataAdapter.Fill(DataSet, "user");
DataTable dataTable = DataSet.Tables[0];
foreach (DataRow dataRow in dataTable.Rows)
{
lbCustomers.Items.Add(dataRow["username"] + " (" + dataRow["password"] + ")");
}
}
}
}