我怎么...我得到一个错误“0号位没有行”从这个vb.net代码 [英] How do i...i get an error "there is no row at position 0" from this vb.net code

查看:47
本文介绍了我怎么...我得到一个错误“0号位没有行”从这个vb.net代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.Data.OleDb
Imports System.Data
Public Class WithdrawandDeposit2
    Dim adapt As New OleDbDataAdapter
    Dim dset As New DataSet
    Dim bal, num As String
    Dim total As Integer
    Function draw()
        cn = New OleDb.OleDbConnection
        With cn
            .ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Maccount.accdb"
            .Open()
        End With
        Dim dt As New DataSet("NewAccount")
        'Dim rs As New OleDb.OleDbDataAdapter(" Select Samount from NewAccount where Samount = '" + lblamount.Text + "'", cn)
        Dim rs As New OleDb.OleDbDataAdapter(" Select * from NewAccount where Saccountno = '" + TextBox1.Text + "'", cn)
        rs.Fill(dt)
        If .Tables(dt).rows.count > 0 Then
            bal = dt.Tables(0).Rows(0)(6).ToString()
            num = dt.Tables(0).Rows(0)(0).ToString()
            TextBox2.Text = dt.Tables(0).Rows(0)(2).ToString()
            Return 0
        End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Val(WithBox.Text) > bal Then
            LowerBalance.Show()
        ElseIf Me.WithBox.Text = "" Then
            Errorform1.Show()
        Else
            total = bal - Val(WithBox.Text)
            Dim dbcommand As String = "update NewAccount set Samount = '" & total & "'where AccountName='" & TextBox1.Text & "'"
            adapt = New OleDbDataAdapter(dbcommand, cn)
            dset = New DataSet
            adapt.Fill(dset)
            'rs.Dispose()
            'cn.Close()
            Call draw()

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        Transactions.Show()
    End Sub

    Private Sub WithdrawandDeposit2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call draw()
        TextBox2.Enabled = False
    End Sub
End Class





我尝试过:



i在bal = dt.tables(0).rows(0)(6)中出错.ToString()



What I have tried:

i am getting an error in bal = dt.tables(0).rows(0)(6).ToString()

推荐答案

它就像错误消息所说的那样简单:该表的行索引0处没有行。桌子是空的。在上面的一行,你似乎检查行数,但它显然是一个你在那里检查的不同的表。也许它看起来应该是这样的?:



It's as simple as the error message states: There is no row at row-index 0 of that table. The table is empty. At the line above you seem to check for the row count but it's apparently a different table you're checking there. Maybe it should look like this instead?:

If dt.Tables(0).Rows.Count > 0 Then


这篇关于我怎么...我得到一个错误“0号位没有行”从这个vb.net代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆