Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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.net - Fatal编程技术网

Vb.net 连接必须有效并已打开

Vb.net 连接必须有效并已打开,vb.net,Vb.net,这里是我的真实代码。当我调试时,我有错误连接必须有效并打开 第testNamebox.Text=cmd.ExecuteScalar()行出错 Private子按钮x1\u单击(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnSave。单击 尝试 Dim TotalResulten为Int16=0 Dim totalResultFr作为Int16=0 调暗时间为Int16=0 frmSavingData.Show() 对于i A

这里是我的真实代码。当我调试时,我有错误连接必须有效并打开

testNamebox.Text=cmd.ExecuteScalar()行出错

Private子按钮x1\u单击(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnSave。单击
尝试
Dim TotalResulten为Int16=0
Dim totalResultFr作为Int16=0
调暗时间为Int16=0
frmSavingData.Show()
对于i As Integer=0到Me.DataGridView1.RowCount-1
如果Me.DataGridView1.Rows(i).Cells(2).Value=“Polynucléaires嗜中性粒细胞”或Me.DataGridView1.Rows(i).Cells(2).Value=“Polynucléaires嗜中性粒细胞”或_
Me.DataGridView1.Rows(i).Cells(2).Value=“Polynucléaires嗜碱性粒细胞”或Me.DataGridView1.Rows(i).Cells(2).Value=“淋巴细胞”或_
Me.DataGridView1.Rows(i).Cells(2).Value=“Monocytes”然后
TotalResulten=TotalResulten+Val(Me.DataGridView1.Rows(i).Cells(4).Value)
totalResultFr=totalResultFr+Val(Me.DataGridView1.Rows(i).Cells(3).Value)
时间=时间+1
如果结束
下一个
如果TotalResulten 100且时间=5,则
MsgBox(“请检查测试Hg的英文结果!”,MsgBoxStyle.OkOnly,“总结果”)
出口接头
如果结束
如果totalResultFr 100且时间=5,则
MsgBox(“请检查测试Hg的法语结果!”,MsgBoxStyle.OkOnly,“总结果”)
出口接头
如果结束
Dim cmd作为MySqlCommand,粗体作为Integer=0,选中打印作为Int16=0
将testNamebox设置为新的RichTextBox
testNamebox.Width=500
testNamebox.Height=50
对于i As Integer=0到Me.DataGridView1.RowCount-1
Dim fr_结果为字符串
Dim eng_结果为字符串
cmd=New MySqlCommand(“从Testdetail where testid=“&Me.DataGridView1.Rows(i).Cells(2).Tag,Setting.cn中选择testName”)
'cmd=New MySqlCommand(“从Testdetail中选择testName,testid=”&Me.DataGridView1.Rows(i.Cells(2.Tag&“”,Setting.cn)
testNamebox.Text=cmd.ExecuteScalar()
如果testNamebox.Lines.GetUpperBound(0)>0,则“控制RichTextBox中的行数”
testNamebox.Text=Me.DataGridView1(3,i).Value.ToString
如果testNamebox.Lines.GetUpperBound(0)>0,则
如果为Nothing(Me.DataGridView1(4,i).Value),则eng_result=“”否则eng_result=Me.DataGridView1(4,i).Value.ToString
如果为Nothing(Me.DataGridView1(3,i).Value),则fr_result=“”否则fr_result=Me.DataGridView1(3,i).Value.ToString
其他的
如果为Nothing(Me.DataGridView1(4,i).Value),则为eng_result=“”+vbCrLf+Me.DataGridView1(4,i).Value.ToString
如果为Nothing(Me.DataGridView1(3,i).Value),则fr_result=“”否则fr_result=“”+vbCrLf+Me.DataGridView1(3,i).Value.ToString
如果结束
其他的
如果为Nothing(Me.DataGridView1(4,i).Value),则eng_result=“”否则eng_result=Me.DataGridView1(4,i).Value.ToString
如果为Nothing(Me.DataGridView1(3,i).Value),则fr_result=“”否则fr_result=Me.DataGridView1(3,i).Value.ToString
如果结束
如果Me.DataGridView1(7,i).Value=True,则bold=1
如果Me.DataGridView1(8,i).Value=True,则选中print=1
cmd=New MySqlCommand(“更新发票详细信息集EngResult=””&_
eng\u result.ToString.Replace(“\”,“\”)。Replace(“”,“”)&“,FrResult=”&fr\u result.ToString.Replace(“\”,“\”)。Replace(“,”)&”_
“',Bold='”&Bold&“',checkprint='”&checkprint&“'where testid='”&Me.DataGridView1.Rows(i).Cells(2.Tag&“’和invoiceid='””&Me.DataGridView1.Rows(i.Cells(0.Tag&“”,Setting.cn)
cmd.ExecuteNonQuery()
如果Me.DataGridView1.Rows(i).Cells(0).Value“”和Me.DataGridView1.Rows(i).Cells(8).Value=False,则
cmd=New MySqlCommand(“Update invoicedetail set checkprint=0,其中TestID=”&Me.DataGridView1.Rows(i.Cells(2.Tag&“)和invoiceid=””&Me.DataGridView1.Rows(i.Cells(0.Tag&“”,Setting.cn)
cmd.ExecuteNonQuery()
ElseIf Me.DataGridView1.Rows(i).Cells(0).Value“”和Me.DataGridView1.Rows(i).Cells(8).Value=True然后
cmd=New MySqlCommand(“Update invoicedetail set checkprint=1,其中TestID='”&Me.DataGridView1.Rows(i.Cells(2.Tag&“)和invoiceid='”&Me.DataGridView1.Rows(i.Cells(0.Tag&“”,Setting.cn)
cmd.ExecuteNonQuery()
如果结束
cmd.Dispose()
粗体=0
选中打印=0
frmSavingData.Refresh()
下一个
cmd=New MySqlCommand(“Update invoicedetail set EngObservation=“&IIf(txtEnglishObservation.Text”“””)&txtEnglishObservation.Rtf.Replace(“”,“”)。Replace(“\”,“\”,“\”,“NULL”)&_
“,FrObservation=“&IIf(txtFrenchObservation.Text”“”””&txtFrenchObservation.Rtf.Replace(“,”)。Replace(“\”,“\”)&“,”NULL“)&”_
“其中testid='”&TestIDforupdate&“'和invoiceid='”&InvoiceNo&“'”,Setting.cn)“testid”
cmd.ExecuteNonQuery()
cmd.Dispose()
“”MsgBox(“保存成功!”)
“我,关上()
frmSavingData.Dispose()
特例
frmSavingData.Dispose()
MsgBox(例如消息)
结束尝试
端接头
这很难
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim totalResultEng As Int16 = 0
            Dim totalResultFr As Int16 = 0
            Dim time As Int16 = 0
            frmSavingData.Show()
            For i As Integer = 0 To Me.DataGridView1.RowCount - 1
                If Me.DataGridView1.Rows(i).Cells(2).Value = "Polynucléaires neutrophiles" Or Me.DataGridView1.Rows(i).Cells(2).Value = "Polynucléaires éosinophiles" Or _
                    Me.DataGridView1.Rows(i).Cells(2).Value = "Polynucléaires basophiles" Or Me.DataGridView1.Rows(i).Cells(2).Value = "Lymphocytes" Or _
                   Me.DataGridView1.Rows(i).Cells(2).Value = "Monocytes" Then
                    totalResultEng = totalResultEng + Val(Me.DataGridView1.Rows(i).Cells(4).Value)
                    totalResultFr = totalResultFr + Val(Me.DataGridView1.Rows(i).Cells(3).Value)
                    time = time + 1
                End If
            Next
            If totalResultEng <> 100 And time = 5 Then
                MsgBox("Please Check English Resultn Of Test Hg !", MsgBoxStyle.OkOnly, "Total Result")
                Exit Sub
            End If
            If totalResultFr <> 100 And time = 5 Then
                MsgBox("Please Check French Result Of Test Hg !", MsgBoxStyle.OkOnly, "Total Result")
                Exit Sub
            End If
            Dim cmd As MySqlCommand, bold As Integer = 0, checkprint As Int16 = 0
            Dim testNamebox As New RichTextBox
            testNamebox.Width = 500
            testNamebox.Height = 50
            For i As Integer = 0 To Me.DataGridView1.RowCount - 1
                Dim fr_result As String
                Dim eng_result As String
                cmd = New MySqlCommand("select testName from Testdetail where testid =" & Me.DataGridView1.Rows(i).Cells(2).Tag, Setting.cn)
                ' cmd = New MySqlCommand("select testName from Testdetail where testid ='" & Me.DataGridView1.Rows(i).Cells(2).Tag & "'", Setting.cn)
                testNamebox.Text = cmd.ExecuteScalar()
                If testNamebox.Lines.GetUpperBound(0) > 0 Then  'control number of lines in RichTextBox
                    testNamebox.Text = Me.DataGridView1(3, i).Value.ToString
                    If testNamebox.Lines.GetUpperBound(0) > 0 Then
                        If IsNothing(Me.DataGridView1(4, i).Value) Then eng_result = "" Else eng_result = Me.DataGridView1(4, i).Value.ToString
                        If IsNothing(Me.DataGridView1(3, i).Value) Then fr_result = "" Else fr_result = Me.DataGridView1(3, i).Value.ToString
                    Else
                        If IsNothing(Me.DataGridView1(4, i).Value) Then eng_result = "" Else eng_result = "" + vbCrLf + Me.DataGridView1(4, i).Value.ToString
                        If IsNothing(Me.DataGridView1(3, i).Value) Then fr_result = "" Else fr_result = "" + vbCrLf + Me.DataGridView1(3, i).Value.ToString
                    End If
                Else
                    If IsNothing(Me.DataGridView1(4, i).Value) Then eng_result = "" Else eng_result = Me.DataGridView1(4, i).Value.ToString
                    If IsNothing(Me.DataGridView1(3, i).Value) Then fr_result = "" Else fr_result = Me.DataGridView1(3, i).Value.ToString
                End If

                If Me.DataGridView1(7, i).Value = True Then bold = 1
                If Me.DataGridView1(8, i).Value = True Then checkprint = 1
                cmd = New MySqlCommand("Update invoicedetail set EngResult='" & _
                                            eng_result.ToString.Replace("\", "\\").Replace("'", "''") & "', FrResult='" & fr_result.ToString.Replace("\", "\\").Replace("'", "''") & _
                                            "',Bold='" & bold & "',checkprint='" & checkprint & "' where testid='" & Me.DataGridView1.Rows(i).Cells(2).Tag & "' and invoiceid='" & Me.DataGridView1.Rows(i).Cells(0).Tag & "'", Setting.cn)
                cmd.ExecuteNonQuery()
                If Me.DataGridView1.Rows(i).Cells(0).Value <> "" And Me.DataGridView1.Rows(i).Cells(8).Value = False Then
                    cmd = New MySqlCommand("Update invoicedetail set checkprint=0 where  TestID = '" & Me.DataGridView1.Rows(i).Cells(2).Tag & "' and invoiceid='" & Me.DataGridView1.Rows(i).Cells(0).Tag & "'", Setting.cn)
                    cmd.ExecuteNonQuery()
                ElseIf Me.DataGridView1.Rows(i).Cells(0).Value <> "" And Me.DataGridView1.Rows(i).Cells(8).Value = True Then
                    cmd = New MySqlCommand("Update invoicedetail set checkprint=1 where  TestID = '" & Me.DataGridView1.Rows(i).Cells(2).Tag & "' and invoiceid='" & Me.DataGridView1.Rows(i).Cells(0).Tag & "'", Setting.cn)
                    cmd.ExecuteNonQuery()
                End If
                cmd.Dispose()
                bold = 0
                checkprint = 0
                frmSavingData.Refresh()
            Next
            cmd = New MySqlCommand("Update invoicedetail set  EngObservation=" & IIf(txtEnglishObservation.Text <> "", "'" & txtEnglishObservation.Rtf.Replace("'", "''").Replace("\", "\\") & "'", "NULL") & _
                                           ", FrObservation=" & IIf(txtFrenchObservation.Text <> "", "'" & txtFrenchObservation.Rtf.Replace("'", "''").Replace("\", "\\") & "'", "NULL") & _
                                           " where testid='" & TestIDforupdate & "' and invoiceid='" & InvoiceNo & "'", Setting.cn) 'TestID
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            '' MsgBox("Save successed!")
            'Me.Close()
            frmSavingData.Dispose()
        Catch ex As Exception
            frmSavingData.Dispose()
            MsgBox(ex.Message)
        End Try
    End Sub
cmd = New MySqlCommand("select testName from Testdetail where testid =" & Me.DataGridView1.Rows(i).Cells(2).Tag, Setting.cn)
testNamebox.Text = cmd.ExecuteScalar()
    cmd = New MySqlCommand("select testName from Testdetail where testid =" & Me.DataGridView1.Rows(i).Cells(2).Tag, Setting.cn)
    Try
        cmd.Connection.Open()
        testNamebox.Text = cmd.ExecuteScalar()
    Catch ex As Exception
        'Handle Error
        testNamebox.Text = ""
    Finally
        cmd.Connection.Close()
    End Try