日期:2014-05-18  浏览次数:21221 次

winform中怎样通过DataGridView读取整列数据(高手请进)
string strselect = "select Name from Document";
  OleDbConnection conn = null;
  OleDbCommand cmd = null;
  try
  {
  conn = DB.Createconnection();
  conn.Open();
  cmd = new OleDbCommand(strselect, conn);
  OleDbDataReader sdr = cmd.ExecuteReader();
  System.Collections.ArrayList list = new System.Collections.ArrayList();
  while (sdr.Read())
  {
  if (!sdr.IsDBNull(sdr.GetOrdinal("Name")))
  {
  list.Add(sdr.GetValue(sdr.GetOrdinal("Name")));
  }
  }
  sdr.Close();
请问有没有好的办法实现从数据库中读取整列的值存进数组里面呀,这个读取的和实际数据库里面的数据不一样,总会有重复的
各位提建议可以完全抛开上面的这个思路
先多谢啦!

------解决方案--------------------
在查的时候把重复的去掉
string strselect = "select distinct Name from Document";
------解决方案--------------------
读取整列 hashtable 吧 hashtable[列名] = 值 用foreach 读
------解决方案--------------------
this.dataGridView2.SelectedCells[5].Value.ToString();

这样就可以读取了啊
------解决方案--------------------
DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGridView.CurrentRow.Index];

------解决方案--------------------
string strselect = "select distinct Name from Document";
OleDbConnection conn = null;
OleDbCommand cmd = null;
try
{
conn = DB.Createconnection();
conn.Open();
cmd = new OleDbCommand(strselect, conn);
OleDbDataReader sdr = cmd.ExecuteReader();
System.Collections.ArrayList list = new System.Collections.ArrayList();
while (sdr.Read())
{
list.Add(sdr["Name"]);
}
sdr.Close();
------解决方案--------------------
string strselect = "select distinct Name from Document"; 
datagridview 的话只有循环了