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
using System.Data.SqlClient
namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
}
private void Form1_Load(object sender, EventArgs e)
{
// 实例化得到一个数据集
DataSet ds = new DataSet()
// 获得连接对象
String connString = "Data Source=.;Initial Catalog=dbok;User ID=sa;Password=root123123"
SqlConnection conn = new SqlConnection(connString)
// 获得DataAdapter对象
String sql = "select * from sanguo"
//SqlDataAdapter adapter = new SqlDataAdapter(sql,conn)
SqlDataAdapter adapter = new SqlDataAdapter()
SqlCommand cmd = new SqlCommand(sql, conn)
adapter.SelectCommand = cmd
Console.WriteLine(adapter)
// 把小车装的货倒入数据集中
adapter.Fill(ds, "one")
cbName.DataSource = ds.Tables["one"]
cbName.DisplayMember = "name"
cbName.ValueMember = "id"
}
}
}
