namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private DataTable d1 = new DataTable();
private SqlDataAdapter sd = new SqlDataAdapter();
private void Form1_Load(object sender, EventArgs e)
{
ds.Tables.Add(d1);
string sqlConnection = "Data Source=.;Initial Catalog=mySQL;Integrated Security=True";
string sql = "select * from Table_login";
SqlConnection conn = new SqlConnection(sqlConnection);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
sd.SelectCommand = com;
sd.Fill(ds.Tables[0]);
sql = "select * from Table_1";
com = new SqlCommand(sql, conn);
sd.SelectCommand = com;
sd.Fill(ds, "d1");
dataGridView1.DataSource = ds.Tables[0];//ds.Tables[索引],此索引并不等同于往dataset里添加datatable的顺序。
//如需按datatable名,则需按下面的格式
//dataGridView1.DataSource = ds.Tables["d1"];
sd.Dispose();
com.Dispose();
conn.Close();
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交