数据库读取数据并赋给一个arraylist

lc12d 2008-04-28 03:45:43
string connectionString = ConfigurationManager.ConnectionStrings["SQLServer"].ConnectionString;
SqlConnection Connection = new SqlConnection(connectionString);
Connection.Open(); //联接打开
string zjid = "select id from [zj_trainlog] where tid='" + tid.Text + "'";
SqlCommand myCommand1 = new SqlCommand(zjid, Connection);
myCommand1.CommandType = CommandType.Text;
SqlDataAdapter myda = new SqlDataAdapter();
myda.SelectCommand = myCommand1;
DataSet ds = new DataSet();
myda.Fill(ds, "news");
Connection.Close();
length = Convert.ToInt32(ds.Tables[0].Rows.Count);
// Response.Write(length);
for (i = 0; i < length;i++ )
{
arrayList.Add(ds.Tables["news"].Rows[i].ToString());
Response.Write(ds.Tables["news"].Rows[i].ToString());
}
怎么ds.Tables["news"].Rows[i].ToString()的值是这些东西啊
System.Data.DataRowSystem.Data.DataRowSystem.Data.DataRowSystem.Data.DataRow
那我想把数据库读出的内容赋给一个arraylist该怎么实现呢。请教了
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lc12d 2008-04-28
  • 打赏
  • 举报
回复
谢谢了,呵呵
refeiner 2008-04-28
  • 打赏
  • 举报
回复
当然了。。你这个表示的是一个数据行
应该是这个Tables["news"].Rows[i][0].ToString();
0表于第一列。你反正只查出一列数据
xieyongbao 2008-04-28
  • 打赏
  • 举报
回复
ds.Tables["news"].Rows[i]["id"].ToString();
没有列名称

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧