如何以更好的速度查询数据?

时间:2016-11-01 17:05:18

标签: mysql backgroundworker

我恳求以更快的速度处理查询数据。已经尝试过使用,索引或存储过程,但仍然经常无法获取数据的值(数据有时空了)。

表格(tbl_Phonebook)包含数千个包含电话号码和电话所有者姓名的数据。

谢谢

这是MyCode:

Private Sub FrmLogger_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Timer1.Interval = 50
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    'check data (phonenumber) in ChannelData

    For i = 0 To 31 'length of objChannelData
        If objChannelData(i) <> "" Then
            DataGridView1.Rows(i).Cells.Item(1).Value() = objChannelData(i) 'the value is PhoneNumber 
            DataGridView1.Rows(i).Cells.Item(2).Value() = GetPhoneBookName(objChannelData(i)) ' try to get Name of PhoneNumber owner  
        End If
    Next
End Sub

Private Function GetPhoneBookName(ByVal nPhoneNumber As String) As String
    'check db connection
    Try
        If (Conn_MySQL.State = ConnectionState.Closed) Then
            Conn_MySQL.Open()
        End If
        'get value from table 
        Dim strSQL As String = "select fPhoneName from tbl_Phonebook where fPhoneNumber = '" & nPhoneNumber & "'"
        Dim myCommand As New MySqlCommand(strSQL, Conn_MySQL)
        Dim myReader As MySqlDataReader
        myReader = myCommand.ExecuteReader()
        myReader.Read()

        If myReader.HasRows Then
            If Not IsDBNull(myReader.GetValue(0)) Then
                Return myReader.GetString(0)
            Else
                Return ""
            End If
            myReader.Close()
        Else
            Return ""
        End If
    Catch ex As Exception
        Return ""
    End Try
End Function

0 个答案:

没有答案