我目前正在一个项目上,想在form_load上将调用的数据加载到datagridview上,但是我不确定为什么没有加载假定的数据。附上我的代码,您能帮我找出这是怎么回事吗?迫切需要它。
代码:
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = GetV9_data();
}
private DataTable GetV9_data()
{
DataTable V9db = new DataTable();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source = 10.47.48.80; Initial Catalog = V9_Hirata_L2; User ID = Guest; Password = ************;";
SqlCommand cmd = new SqlCommand("Select ID, MotorSN, StationNo, PT_NestNo, PT_TS_AW_Pin_1, PT_TimeIn FROM tbl_V9_Datalog", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
V9db.Load(reader);
return V9db;
}