我正在尝试将表单文本框中的字段参数传递给函数,以根据我传递的数据表参数创建新列表对象。
在下面的代码中,第一个tmpReadTable显示没有语法错误,但是当我尝试使用具有Datatable名称的Parm时,我不确定我在语法上缺少什么。我是这个新手,在此先感谢!
[感谢您提供所有有用的回复...对不起,我没有更多的经验,我来自Visual Foxpro。
总结:
我在Murach的VB书中找到了此示例,但他在较早的练习中没有介绍如何从PRODUCTS表中创建LIST。所以我想我可以用传递的cImportTable代替它做同样的事情……那是我遇到的麻烦,也许大家都知道更好的方法。
私有函数ReadImportFile(ByVal cImportFile作为字符串,ByVal cGroupID作为字符串,ByVal cControlTable作为字符串,ByVal cImportTable作为字符串)
MessageBox.Show(cImportFile + " " + cGroupID + " " + cControlTable)
If Not File.Exists(cImportFile) Then
MessageBox.Show("File: " + cImportFile + " does not exist - cancelling process.")
Return False
End If
Dim curFileStream As New StreamReader(New FileStream(cImportFile, FileMode.Open, FileAccess.Read))
Dim curImportTable = "NewDataSet." + cImportTable
'Here I'm trying to create a LIST or DATASET using my Empty SQL Import Table and read in each row of the CSV file in the DO WHILE loop
'...I'm coming from Visual Foxpro background so am not sure what I'm missing or what is the standard procedure to do this simple task.
'This line gives me a syntax issue - and I'm not even sure what it's suppose to do, I'm taking it from Murach's VB book example,
'but he leaves out this vital piece of how to create this LIST from a Datatable - or if it's even the right method to use.
Dim tmpReadTable = New List(Of curImportTable)
Do While curFileStream.Peek <> -1
Dim row As String = curFileStream.ReadLine
Dim columns() As String = row.Split(",")
'Dim ImportRecord As New NewBenefitsDataSet.FO_HealthcareHighways_ImportRow
Dim ImportRecord As New curImportTable
ImportRecord.GroupId = columns(0)
ImportRecord.MemberId = columns(1)
Loop
'More Processing after Importing CSV file.....
curFileStream.Close()
'If lNoErrors
Return True
结束功能
[您在此处的代码行3上使用的是变量而不是TYPE
' This seems to be ok, no syntax error
Dim tmpReadTable = New List(Of NewDataSet.FO_ImportDataTable)
' The variable below implicitely will be of STRING type
Dim curImportTable = "NewDataSet." + cImportTable.ToString
' This line is not going to work
Dim tmpReadTable = New List(Of curImportTable)
' BUT THIS WILL
Dim x = New List(Of String)
另一个问题是Dim tmpReadTable
在您的代码中发生了两次!无法重新声明变量。最重要的是,您将其声明为NewDataSet.FO_ImportDataTable
此外,我建议声明所有变量,例如Dim curImportTable as String
,这样您可以更轻松地识别类型。当您使用匿名类型,LINQ等时,Option Infer
很好