DataReader如何根据字段名取值?

nmxue 2003-06-11 05:07:48
我看到getString之类的方法只有整形的参数啊,又没有根据字段的name取值得?
...全文
240 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nmxue 2003-06-11
  • 打赏
  • 举报
回复
谢谢大家~~~怎么给分啊?~~~
xswh418 2003-06-11
  • 打赏
  • 举报
回复
两中方法:
1比如你要取的一个int值,是返回记录集的第一个字段age
datareader1.getint(0);
2
int.prase(datareader1["age"].tostring());
declude 2003-06-11
  • 打赏
  • 举报
回复
Datareader["字段名"]
wn_319 2003-06-11
  • 打赏
  • 举报
回复
you
寒星 2003-06-11
  • 打赏
  • 举报
回复
using System;
using System.Data.SqlClient;

public class DataReader
{
public static void Main(string[] args)
{
string source = "Data Source=xxx;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xxxx;";

string sql = "Select Name,FullName From OnUser";

SqlConnection conn = new SqlConnection(source);

conn.Open();

SqlCommand cmd = new SqlCommand(sql,conn);

SqlDataReader aReader = cmd.ExecuteReader();

while(aReader.Read())
Console.WriteLine("'{0}' from {1}",aReader["Name"].ToString(),aReader["FullName"].ToString());

Console.WriteLine("***OK***");

aReader.Close();
conn.Close();
}
}
JJ77 2003-06-11
  • 打赏
  • 举报
回复
returnReader[].

110,571

社区成员

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

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

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