English 中文(简体)
KODataReader发现每行的价值
原标题:SQLDataReader find value of each row

I used to use datasets instead of sqldatareaders and I used to be able to do something like this

If dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
   lbl.Text = dataset.tables(0).Rows(0)(2).ToString()) 
Else
    Do Nothing
End If

这显然与制图师合作。

我有密码,看卡塔里德人是否拥有任何增长,但想知道是否有办法获得每个增长的价值。

我猜想这一点是可能的,一看一看一看,但似乎看不到什么。

Dim conn As SqlConnection = New SqlConnection("server= h ; user id= w ; password= w ; database= w ; pooling= false ")  

conn.Open()  

Dim query As New SqlCommand("DECLARE @investor varchar(10), @sql varchar(1000) Select @investor = 69836 select @sql =  SELECT * FROM OPENQUERY(db,  SELECT * FROM table WHERE investor =       + @investor +        )  EXEC(@sql)", conn) 

Dim oDR As SqlDataReader = query.ExecuteReader()

If oDR.HasRows or dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
   lbl.Text = dataset.tables(0).Rows(0)(2).ToString())
Else
    Do Nothing
End If

这就是我目前显然不工作的守则。

任何想法?

增 编

问题回答

当你使用数据阅读器时,你必须逐行走。 利用HasRows是一个良好的开端,因为如果返回的结果是空的,它将告诉你。

通过这一结果,你应使用“阅读”方法。 如果在你过去一行走时,你一行不实,就会回去。

我的Vb是贫穷的,因此我将在C#中举例说明:

if (oDR.HasRows && oDR.Read()) 
{
  if (oDR.GetString(0) == "N")
  {
    lbl.Text = oDr.GetString(1);
  }  
}

我在此首先检查的是,我们得出了数据的结果,然后试图进入第一行。 如果是这样,我就读了第一栏的直观价值,将其与“N”相比较。 如果该数值等于“N”,则将卢布变量的正文财产确定为第二栏的示意图。

这应等于您对数据集的算法。 我建议你阅读MSDN提供的文件。 这种做法非常好,示范守则很有用。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签