标签:style blog http color os 使用 io for ar
sqlDataReader类提供了FieldCount属性,可确定查询反悔了多少个字段。
sqlDataReader中没有指示可用行的属性。
使用sqlDataReader的GetName方法,该方法接受一个Int整数,指定字段的序号,并在一个字段中返回其名称。
要确定用于存储在一特定字段的内容的.NET数据类型,请使用SqlDataReader的GetFieldType方法,与GetName方法类似,接受一个Int整数类型,指定字段的序号,
GetFieldType方法在Typed对象中返回其数据类型。
SqlDataReader的GetDataTypeName方法,接受一个Int整数,返回一个字符串,其中有该字段在数据库中的数据类型。
 
 1            string connstr =@"DataSource=ZHANG-C;InitialCatalog=sq;Integrated Security=True"; 
 2             string strSQL = "select * from T_Code";
 3             SqlConnection conn = new SqlConnection(connstr);
 4             conn.Open();
 5             SqlCommand cmd = new SqlCommand();
 6             cmd.Connection = conn;
 7             cmd.CommandText = strSQL;
 8 
 9             SqlDataReader read = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
10             for (int i = 0; i < read.FieldCount; i++)
11             {
12                 Console.WriteLine("行号: {0}",i);
13                 Console.WriteLine("字段名称:{0}",read.GetName(i));
14                 Console.WriteLine(".NET中数据类型名称:{0}",read.GetFieldType(i).Name);
15                 Console.WriteLine("数据库中数据类型名称:{0}",read.GetDataTypeName(i));
16             }
标签:style blog http color os 使用 io for ar
原文地址:http://www.cnblogs.com/zhangyuanbo12358/p/3940508.html