问题描述
大家好,
我有问题.
状况:
我已经声明了一个字符串来保存查询中的数据
Hi all,
I have a problem.
Situation:
I have declared a string to hold the data from a query
strSQL=GetPayment(strDateFrm,strDateTo)
cnCMD = New OleDbCommand(strSQL, cnDB)
cnCMD.CommandType = CommandType.Text
rdr = cnCMD.ExecuteReader
If Not (IsNothing(strSQL)) Then
If rdr.Read Then -------> "problem occurs here"
While rdr.Read
我想问一个能解决我问题的人:
如果数据库中的数据为空,该怎么办?因为当数据库中不存在数据时,它将填充为DataSet
的空白,并且DataReader
将找不到任何内容,并跳过我在数据库中没有输入条件的步骤,它将填充"-NA-"字符串值. br/>
或者谁能告诉我将数据库中的数据插入到DataSet
的其他代码.
我对在搜索引擎中找到的答案感到困惑,因为大多数情况下,它们会将数据放入ListView
,DataGridView
之类的文件中.
这让我感到困惑.
我使用对象objPayment
作为介质从数据库检索数据并填写DataSet
列.
例如:
I want to ask anyone who can solve me for:
If data from database is empty, what should I do? Because when data is not exist in database, it will fill empty to DataSet
and DataReader
will find nothing and skip the step where I put a condition if nothing in database, it will fill "-NA-" string value.
Or can anyone tell me the other code for inserting data from database to DataSet
.
I''m confused about the answer that I found in search engine because mostly they put the data into something such as ListView
, DataGridView
.
It confuses me.
I use an object objPayment
as medium to retrieve data from database and fill in DataSet
column.
For example:
If Not (IsDBNull(rdr("intMPAJRecpNo"))) Then
objChqDataRow.strReceiptNo = rdr("intMPAJRecpNo")
Else
objChqDataRow.strReceiptNo = "- NA -"
End If
如果有人无法使用DataReader
处理数据,请帮忙.
If someone has the other way from my way to manipulate data from using DataReader
, kindly help me.
推荐答案
While rdr.HasRows ANDALSO rdr.Read
'... code ...
End While
如果您这样做:
If you do this:
If rdr.Read Then
While rdr.Read
您实际上是在两次调用.Read
时跳过了一行(在IF
上再次输入WHILE
).
You are actually skipping a row as you are calling .Read
twice (Once on IF
and again entering your WHILE
).
这篇关于将数据从Access DB填充到vb.net数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!