对,就是将查询出来的结果集保存到了sqldatareader对象中,这个对象你可以把它想象成一张虚拟表,执行一次dr.read()就会下移一行,里面每列用dr.getstring()等方法取
1、sqldatareader这个对象没有public声明的构造函数,所以不能通过new sqldatareader()这种形式创建对象.这和.net的fcl类型控制有关,还有这个对象本身的性质有关.2、至于使用使用sqlcommand来返回sqldatareader,目的是保证sqldatareader内容的实现细节不对用户开放,也符合面向对象的设计原则.
sdr["ID"]是数据库表中的ID sdr["ID"]返回的是object类型, 用.ToString()返回string
按我的理解SqlDataReader dr=cd.ExecuteReader();SqlDataReader dr 这个时候声明dr 但是 dr是null 比如 SqlDataReader是白培房dr可以看成一个空地cd.ExecuteReader() 返回了一个dr对象 赋值到 声明的dr 一个装修好的房子然后依样画葫芦
你需要先把SqlConnection到实例调用.open()方法 才能用SqlDataReader
得到特定需要的对象,如果会在不同的方法中用到同一对象,我们常常把此对象在类变量中进行声明,在用到时,new一次来构造它SqlDataReader sa只是声明一个SqlDataReader类的对象,并没有东西与其关联.而在SqlDataReader sa=new SqlDataReader()中,声明变量的同时,通过new操作符调用其构造函数.在编程中,即楼上说的sa=new SqlDataReader(); 此对象构造后不影射类变量
reader.FieldCount获取字段数目
sqlconnection con=new sqlconnection("连接字符串");连接sqlcommand SQL命令 比如 select * from abcsqldatareader,只读数据sqldataadapter SQL命令的中间人两个都是读数据库取数据的用法不一样datatable 是dataset的具体对象
string cnn = ConfigurationManager.ConnectionStrings["ReportDataService"].ConnectionString; using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = cnn; cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.
sqlcmd1.CommandText = "select customername from customers order by customercode"; sqldr1 = sqlcmd1.ExecuteReader(); while (sqldr1.Read()) { comboBox2.Items.Add(sqldr1.GetString(0)); } sqldr1.Close();