Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 我需要知道如何避免vb 2010中的System.Data.DataRowview_Vb.net_Vb.net 2010_Filewriter_Databound Controls - Fatal编程技术网

Vb.net 我需要知道如何避免vb 2010中的System.Data.DataRowview

Vb.net 我需要知道如何避免vb 2010中的System.Data.DataRowview,vb.net,vb.net-2010,filewriter,databound-controls,Vb.net,Vb.net 2010,Filewriter,Databound Controls,我的代码有问题;如果能帮她做我想做的事而不犯令人讨厌的错误,我将不胜感激。读取数据绑定列表框字符串,找到用户选择的字符串并将所述字符串写入文件 Private Sub btnContinue_Click(sender As System.Object, e As System.EventArgs) Handles btnContinue.Click ' 1st file and mySQL Update to testing table If txtLocati

我的代码有问题;如果能帮她做我想做的事而不犯令人讨厌的错误,我将不胜感激。读取数据绑定列表框字符串,找到用户选择的字符串并将所述字符串写入文件

    Private Sub btnContinue_Click(sender As System.Object, e
    As System.EventArgs) Handles btnContinue.Click
    '  1st file and mySQL Update to testing table
    If txtLocation.Text.ToString <> "" And txtUnitTested.Text.ToString <> "" Then 
        Dim filewriter As New System.IO.StreamWriter(
               "C:\Users\OER\Documents\Visual Studio 2010\Projects\frmTest1_0.txt")
        Dim curItem = lstCustomer.SelectedItem
        Dim now As DateTime = DateTime.Now
        With filewriter
            .WriteLine(vbCrLf + (now.ToString("F"))) ' Write the DateTime to the file
        End With

        For Each objDataRowView As DataRowView In lstCustomer.SelectedItems
            Dim item As String
            For Each item As DataRowView In Me.lstCustomer.Items.Item("customer")
                item = String.Parse(lstCustomer.SelectedValue)
                WriteLine(curItem(item))
            Next item
        Next '  THIS IS THE FOR LOOP I AM HAVING ISSUES WITH!!!!!!!

        With filewriter
            .WriteLine(vbCrLf + txtLocation.Text + vbCrLf + txtUnitTested.Text)
        End With
        filewriter.Close()
        frmTest1.Show()
    Else
        MsgBox("Please Type the Location and Unit Tested!!!", vbCritical)
        txtLocation.Clear()
        txtUnitTested.Clear()
        txtLocation.Focus()
    End If
Private Sub btn继续\u单击(发送者作为System.Object,e
作为System.EventArgs)处理BTN继续。单击
'第一个文件和mySQL更新到测试表
如果txtLocation.Text.ToString“”和txtnittested.Text.ToString“”,则
Dim filewriter作为新System.IO.StreamWriter(
“C:\Users\OER\Documents\Visual Studio 2010\Projects\frmTest1\u 0.txt”)
Dim curItem=lstCustomer.SelectedItem
立即变暗为DateTime=DateTime.now
使用文件编写器
.WriteLine(vbCrLf+(现在是.ToString(“F”))'将日期时间写入文件
以
对于lstCustomer.SelectedItems中作为DataRowView的每个objDataRowView
将项目设置为字符串
对于Me.lstCustomer.Items.item(“客户”)中作为DataRowView的每个项目
item=String.Parse(lstCustomer.SelectedValue)
书写线(curItem(项目))
下一项
下一步“这是我遇到问题的FOR循环!!!!!”!!!!!!!
使用文件编写器
.WriteLine(vbCrLf+txtLocation.Text+vbCrLf+txtnittested.Text)
以
filewriter.Close()
frmTest1.Show()
其他的
MsgBox(“请键入测试的位置和单元!!!”,vbCritical)
txtLocation.Clear()
txtUnitTested.Clear()
txtLocation.Focus()
如果结束
这些循环:

For Each objDataRowView As DataRowView In lstCustomer.SelectedItems
     Dim item As String
     For Each item As DataRowView In Me.lstCustomer.Items.Item("customer")
         item = String.Parse(lstCustomer.SelectedValue)
             WriteLine(curItem(item))
     Next item
Next 
会给你带来一些问题。您已经声明了一个与另一个变量同名的循环变量。然后给它赋值

另外,我不太清楚这两个循环的目的是什么。我对您在这段代码中试图实现的目标有些困惑。首先,我将重命名此行中的变量:

Dim item as String
我将以此为例:

Dim result as string
如果将其设为其他值,则无法更改循环中item的值(因为这是循环变量)。这将导致错误

将循环内的代码更改为:

result = String.Parse(lstCustomer.SelectedValue)
很可能这仍然不能让你达到你想要去的地方,但这是一个好的开始。除非lstCustomer中的每个项目都包含多个要迭代的项目,否则我认为您可能只需要第一个外部循环

如果循环是这样开始的:

For Each objDataRowView As DataRowView In lstCustomer.SelectedItems
那么我想你会想要:

objDataRowView.Item("customer")
作为输出。我认为这将是表中customer字段的值


您基本上是说此行有一个名为customer….的列。。。。我想要那个值。

你得到了什么“恼人的错误”?我怀疑这是一个
有问题的异常
。不,先生,这更多的是一个逻辑错误(程序将System.Data.DataView添加到我的数据库中),好像列表框中的数据需要单独声明,或者与数据绑定列表一起声明,所以说是的,上面有一个逻辑问题。但是,您能显示加载列表框的代码吗?根据问题,尝试回答时的错误为+1,尽管很难理解发生了什么。谢谢@D;我非常感谢您的回答一旦您整理了循环,我认为您只需要引用数据行中的正确项,而不是数据行本身作为输出。我需要查看您将列表绑定到的数据表的结构,以确保。id主自动递增时间(varchar,40)客户(varchar,40)MyIsam数据库,utf8 unicode\u ci排序规则