这是读取数据的正确语法吗

这是读取数据的正确语法吗

本文介绍了这是读取数据的正确语法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是尝试获取用于读取数据的正确语法,以便使其可用,以便我可以调用该函数....

我看过的数据读起来像..

.CompanyName = CStr(nwDataReader.GetString(1))
.ContactName = CStr(nwDataReader.GetString(2))




我有大约30列要阅读,我是否必须以上述方式调用函数中的每一行,还是有更好的方法?





上一篇:


我正在创建我的基类,并调用一个函数来检索数据.如果我以以下格式读取数据,是否可以在页面后面的代码中调用该函数?

Just trying to get the correct syntax for reading the data so that it it available so that I can call the function....

I''ve seen the data read like..

.CompanyName = CStr(nwDataReader.GetString(1))
.ContactName = CStr(nwDataReader.GetString(2))

Etc.


I have approx 30 columns to read, do I have to call each line in the function in the above manner or is there a better way?





PREVIOUS POST:


I am creating my base class and calling a function to retrieve the data. If I read the data in the following format, will I be able to call the function in the code behind page?

Public Function GetPortfolioInfo(ByVal Contract As String) As PortfolioInfo

Dim Reader...
Dim PortfolioInfo...
Dim Conn..

Do while Read
If IsDBNull(rd("ContractDesc")) = True Then
                   _ContractDesc = ""
               Else : _ContractDesc = "" & CType(rd("ContractDesc"), String)
               End If

               If IsDBNull(rd("Status")) = True Then
                   _Status = ""
               Else : _Status = "" & CType(rd("Status"), String)
               End If

Return PortfolioInfo1
End Function

推荐答案

Dim SQLQuery as string = "Select * from dbTable"
Dim ConnectionString as string = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
Dim DT as DataTable = new system.data.datatable
DT= SQLToDT(ConnectionString, SQLQuery)
CompanyName = DT.rows(0).item(0).tostring











Public Function SQLToDT(ConnectionString As String, SQLQuery As String) As DataTable
    Dim myDTable as system.data.datatable
    Dim conn As New SqlConnection(ConnectionString )
    Dim adapter As New SqlDataAdapter()
    adapter.SelectCommand = new SqlCommand(SQLQuery , conn)
    adapter.Fill(myDTable)
    Return myDTable
End Function


If Not IsDBNull(dbrProducts(1)) Then .Name = dbrProducts.GetString(1) Else .Name = "Default"
If Not IsDBNull(dbrProducts(2))Then.CostPrice = dbrProducts.GetDecimal(2) Else .CostPrice = 0
If Not IsDBNull(dbrProducts(3)) Then .PackSize = dbrProducts.GetInt32(3) Else .PackSize = 0
If Not IsDBNull(dbrProducts(4)) Then .RetailPrice = dbrProducts.GetDecimal(4) Else .RetailPrice = 0



只是一种不同的表达方式,可能更简洁,更易读.希望这会有所帮助.

快乐编码



just a different way of putting it is all maybe a liitle more concise and readable. Hope this helps.

Happy Coding


这篇关于这是读取数据的正确语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:30
查看更多