日期:2014-05-18 浏览次数:20977 次
public void GeiView() { SqlConnection con = null; string ConnectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=PGWEI"; con = new SqlConnection(ConnectionString); try { con.Open(); String sql = "SELECT 客户号,膘厚,级别,重量,头数,类型,日期,时间,操作人 FROM DATAWEI ORDER BY ID DESC";//还有一个ID不需要显示所以没有查 SqlDataAdapter sa = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); sa.Fill(ds, "DATAWEI"); wg.dataGridView1.DataSource = ds.Tables["DATAWEI"]; SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(sa); } catch { MessageBox.Show("获取data失败"); } finally { con.Close(); } }
public void GeiView() { SqlConnection con = null; string ConnectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=PGWEI"; con = new SqlConnection(ConnectionString); try { con.Open(); String sql = "SELECT 客户号,膘厚,级别,重量,头数,类型,日期,时间,操作人 FROM DATAWEI ORDER BY ID DESC"; SqlDataAdapter sa = new SqlDataAdapter(sql, con); DataTable dtbl = new DataTable(); sa.Fill(dtbl); sa.Dispose(); MessageBox.Show(dtbl.Rows.Count.ToString()); wg.dataGridView1.AutoGenerateColumns = false; wg.dataGridView1.Columns.Clear(); var array = new DataGridViewColumn[9]; for (int i = 0; i < array.Length; i++) { array[i] = new DataGridViewTextBoxColumn(); array[i].Width = 100; } array[0].DataPropertyName = array[0].HeaderText = "客户号"; array[1].DataPropertyName = array[1].HeaderText = "膘厚"; array[2].DataPropertyName = array[2].HeaderText = "级别"; array[3].DataPropertyName = array[3].HeaderText = "重量"; array[4].DataPropertyName = array[4].HeaderText = "头数"; array[5].DataPropertyName = array[5].HeaderText = "类型"; array[6].DataPropertyName = array[6].HeaderText = "日期"; array[7].DataPropertyName = array[7].HeaderText = "时间"; array[8].DataPropertyName = array[8].HeaderText = "操作人"; wg.dataGridView1.Columns.AddRange(array); wg.dataGridView1.DataSource = dtbl; SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(sa); } catch { MessageBox.Show("获取data失败"); } finally { con.Close(); } }
------解决方案--------------------
断点可以看到ds里的数据么
------解决方案--------------------