如何解决使用sqldatabase在2位VB.NET上没有行

问题描述 投票:-2回答:1
  1. 私人子费() Dim Query As String Query = "Select * from Charges where DOctype='" & comboBoxTranType.Text & "'" Dim cmd As New SqlCommand(Query, con) con.Open() Dim dataAdapter As New SqlDataAdapter(Query, con) Dim dt As New DataTable dataAdapter.Fill(dt) dataAdapter.Dispose() If dt.Rows.Count > 0 Then LabelV001.Text = dt.Rows(0).Item("Head").ToString() LabelV002.Text = dt.Rows(1).Item("Head").ToString() LabelV003.Text = dt.Rows(2).Item("Head").ToString() End If If dt.Rows.Count > 0 Then LabelFIELD1.Text = dt.Rows(0).Item("Equation").ToString() LabelFIELD2.Text = dt.Rows(1).Item("Equation").ToString() LabelFIELD3.Text = dt.Rows(2).Item("Equation").ToString() End If con.Close() End Sub SIR与你的帮助我之前得到了结果,但是由于FIELDTEXT3的错误原因,即位置2没有行,等式3无法计算,请帮助我,
vb.net-2010
1个回答
0
投票

不知道为什么他们这么快就关闭你的新问题......我正在为它建立一个答案。

  1. 单击Project - > Add Reference
  2. 切换到COM选项
  3. 选择“Microsoft Script Control 1.0”条目,然后单击“确定”。

现在你可以使用如下代码,为textCharges1创建代码 - > V001到textCharges25 - > V025:

Public Class Form1

    Private SC As New MSScriptControl.ScriptControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SC.Language = "VBScript"

        Dim ctl As Control
        Dim ctlName, functionBody As String
        functionBody = "Function {0}()" & vbCrLf & vbTab & "{0} = CDbl({1}.Text)" & vbCrLf & "End Function"
        For i As Integer = 1 To 25
            ctlName = "textCharges" & i
            ctl = Me.Controls.Find(ctlName, True).FirstOrDefault
            If Not IsNothing(ctl) Then
                SC.AddObject(ctlName, ctl, True)
                SC.AddCode(String.Format(functionBody, "V" & i.ToString("000"), ctlName))
            End If
        Next

        LABELFIELD2.Text = "V001*V002/100"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Dim result = SC.Eval(LABELFIELD2.Text)
            lblResult.Text = result
        Catch ex As Exception
            lblResult.Text = "{Error}"
        End Try
    End Sub

End Class

运行示例:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.