
首先在vs2005中引入using System.Data.SqlClient命名空间
/// 查询
/// </summary>
/// <returns></returns>
public DataTable Select()
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESSInitial Catalog=TestIntegrated Security=True")//Initial Catalog后面跟你数据库的名字,如果你的SqlServer服务器名称后面不带SQLEXPRESS,那么Data Source=.
conn.Open()
string sql = "select * from users"
SqlCommand cmd = new SqlCommand(sql, conn)
SqlDataAdapter sda = new SqlDataAdapter(cmd)
DataTable dt = new DataTable()
sda.Fill(dt)
在comboBox 对象的Items的属性里添加 点击后面的三小点 进入添加内容的页面也可以用代码comboBox.Items.Add(string)string为所要添加的内容
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)