goto语句是否有其他替代方法

goto语句是否有其他替代方法

本文介绍了goto语句是否有其他替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6个文本框.
点击保存按钮后,应检查以下内容
如果在文本框4中输入的值以400开头,则保存.
否则,如果文本框4中的值不是以400开头,则与数据库一起检查该值是否存在于数据库中.
如果存在,则保存条目
否则检查文本框5.如果文本框5中的值为29或31,则保存
否则清除字段或不保存..
请帮我.
我是vb.net的新手...

我非常需要它....


我在这里使用了goto语句.还有其他方法可以..你能帮我吗?还是可以继续...找到下面的代码

I have 6 text boxes.
on clicking save button it should check the following
if the value entered in textbox 4 is beginning with 400 then save.
else if value in textbox 4 is not starting with 400 then check with database whether the value exists in database.
if exists save entry
else check for textbox 5. if value in textbox 5 is 29 or 31 then save
else clear field or dont save..
please help me.
i am new to vb.net...
please
i need it very immediately....


I have used goto statement here. Is there any other way to do this.. can u please help me ... or is this fine to proceed... find the below code

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            If (IsNumeric(txtAccNo.Text) = False Or txtAccNo.Text.Trim.Length < 12) Then
                ShowMessage("Enter Account Number")
 ''some validation done here for first three textboxes..
If Mid(ctrl.txtBank_Code.Text, 1, 3) = "400" Then
                    GoTo repeat
                End If

                If Mid(ctrl.txtBank_Code.Text, 1, 3) <> "400" Then
                    Dim Conn1 As New SqlConnection(CONNSTR)
                    Dim cmd1 As New SqlCommand("", Conn1)
                    cmd1.CommandText = "Select MICR_CODE from New_Speed1 where MICR_CODE=''" & _
                                      ctrl.txtBank_Code.Text & "''"
                    Try
                        Conn1.Open()
                        Dim drReader As SqlDataReader = cmd1.ExecuteReader
                        Dim isthr As Boolean = False
                        If drReader.HasRows Then
                            isthr = True
                            ''MsgBox("TEST")
                            Conn1.Close()
                            cmd1.Dispose()
                            Conn1.Dispose()
                            drReader.Read()
                            ctrl.txtBank_Code.Text = drReader.Item("MICR_CODE")
                            drReader.Close()
                            Conn1.Close()
                            cmd1.Dispose()
                            Conn1.Dispose()

                        ElseIf isthr <> True And ((ctrl.txtTran_Code.Text = "29") Or (ctrl.txtTran_Code.Text = "31")) Then
                            GoTo repeat
                        ElseIf isthr <> True And (ctrl.txtTran_Code.Text <> "29" Or ctrl.txtTran_Code.Text <> "31") Then
                            MsgBox("OUT STATION !!!")
                            Exit Sub
                        End If
                    Catch ex As Exception
                        MsgBox("Could not Find Record", MsgBoxStyle.Critical)
                    End Try
                End If


goto语句在这里.单击保存按钮后,它应如上所述进行验证并保存在数据库中

重复:


the goto statement comes here. once i click save button it should validate as mentioned above and save in database

repeat:

Dim cmd As New SqlCommand("Insert_Scanned_Cheques_New01", conn)
               cmd.CommandType = CommandType.StoredProcedure
               cmd.Parameters.Add("Account_No", Data.SqlDbType.VarChar, 12).Value = _
                                  Me.txtAccNo.Text

推荐答案


这篇关于goto语句是否有其他替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 23:02