如何在不存在所需行时显示消息 [英] how to show message when the desirable row is not exist

查看:82
本文介绍了如何在不存在所需行时显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   Public Sub display_data()
        cn.Open()
        Dim dt As New DataTable("shakhes")
        Dim rs As New SqlDataAdapter("select * from shakhes", cn)
        rs.Fill(dt)
        ShakhesDataGridView.DataSource = dt
        ShakhesDataGridView.Refresh()
        Label1.Text = dt.Rows.Count
        rs.Dispose()
        cn.Close()
        ShakhesDataGridView.Columns.Item(0).HeaderText = "year"
        ShakhesDataGridView.Columns.Item(1).HeaderText = "month "
        ShakhesDataGridView.Columns.Item(2).HeaderText = "price"
    End Sub

    Public Sub get_data1()
        cn.Open()
        Dim dt As New DataTable("shakhes")
        Dim rs As New SqlDataAdapter("select * from shakhes where sal_tadieh = '" & TextBoxX4.Text & "' and mah_tadieh = '" & ComboBoxEx3.Text & "'", cn)
        rs.Fill(dt)
        ShakhesDataGridView.DataSource = dt
        ShakhesDataGridView.Refresh()
        Label1.Text = dt.Rows.Count
        rs.Dispose()
        cn.Close()
        If Val(Label1.Text) = 1 Then
            Dim i As Integer
            i = ShakhesDataGridView.CurrentRow.Index
            TextBoxX2.Text = ShakhesDataGridView.Item(2, i).Value
            If ShakhesDataGridView.Item(2, i).Value = 0 Then
                LabelX6.Text = "there is no data"
            Else
                LabelX6.Text = TextBoxX2.Text
            End If
        End If
    End Sub

    Public Sub get_data2()
        cn.Open()
        Dim dt As New DataTable("shakhes")
        Dim rs As New SqlDataAdapter("select * from shakhes where sal_tadieh = '" & TextBoxX4.Text & "' and mah_tadieh = '" & ComboBoxEx3.Text & "'", cn)
        rs.Fill(dt)
        ShakhesDataGridView.DataSource = dt
        ShakhesDataGridView.Refresh()
        Label1.Text = dt.Rows.Count
        rs.Dispose()
        cn.Close()
        If Val(Label1.Text) = 1 Then
            Dim i As Integer
            i = ShakhesDataGridView.CurrentRow.Index
            TextBoxX3.Text = ShakhesDataGridView.Item(2, i).Value
            If ShakhesDataGridView.Item(2, i).Value = 0 Then
                LabelX7.Text = "there is no data"
            Else
                LabelX7.Text = TextBoxX3.Text
            End If
        End If
    End Sub

Private Sub tadieh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       'TODO: This line of code loads data into the 'Ejra_dbDataSet.shakhes' table. You can move, or remove it, as needed.
       Me.ShakhesTableAdapter.Fill(Me.Ejra_dbDataSet.shakhes)
       expo()
       display_data()
   End Sub

   Private Sub ComboBoxEx3_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx3.SelectedIndexChanged
       get_data1()
   End Sub

   Private Sub ComboBoxEx4_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx4.SelectedIndexChanged
       get_data2()
   End Sub

Private Sub ShakhesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
       Me.Validate()
       Me.ShakhesBindingSource.EndEdit()
       Me.TableAdapterManager.UpdateAll(Me.Ejra_dbDataSet)
   End Sub



大家好吧

我制作的app vb.net有一个按钮和一个数据网格视图和两个组合框ex和两个文本框和两个标签

我在数据库中保存了一些数据,我想在更改组合框和文本框的项目时,在数据网格视图中显示所需的数据行

问题是当前行索引存在标签时。文本显示所需的行但当前行索引不存在时,前一行显示在label.text中,但我想更改label.text或消息框或标签。文字显示给用户的消息

有什么建议?我必须在哪个事件中写一些代码?

我的代码不起作用是:


Hi everybody
I make app vb.net that has one button and a data grid view and two combo box ex and two textboxes and two labels
I save some data in a database and I want when change items of combo box and text box the desirable data row showed in data grid view
The problem is that when current row index exist the label. Text show the desirable row but when current row index is not exist the before row showed in label.text but I want to changes label.text or message box or label. Text shows a message for user
What suggestion is there? And I must in which event write some codes?
My code that do not work is :

推荐答案

解决方案原则:



您已经了解当您查找的行不存在时,您显示错误的数据。

解决方案非常简单,检查是否实际行在显示数据或警告信息之前是正确的。

伪代码:

Solution principle:

You have understood that when the row you looking for don't exist, you display wrong data.
The solution is quite simple, Check if actual row is the right one before displaying data or alert message.
Pseudo code:
If (row found) Then
    display Data
Else
    display Alert message
End If


这篇关于如何在不存在所需行时显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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