使用vb.net 2010在mysql中记录计数 [英] Record count in mysql using vb.net 2010

查看:147
本文介绍了使用vb.net 2010在mysql中记录计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有这个代码的问题,想从mysql查看记录到文本框但是当我点击按钮时只会卸载窗口而不会发生。请帮忙,到目前为止这是我的代码供您参考。



Hi guys,

im having problem with this code, a want to view a count of record into a text box from mysql but when i click the button it will only unload the window and nothings happen. Please help, so far this is my code for your reference.

Imports MySql.Data.MySqlClient

Public Class frm_login
    Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click
        txt_count.Text = idverifier()
        frm_main.txt_remshd.Text = txt_login.Text
    End Sub

    Private Sub pb_exit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pb_exit1.Click
        '  End
    End Sub

    Private Sub txt_login_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_login.TextChanged
        Me.txt_login.CharacterCasing = CharacterCasing.Upper
    End Sub

    Function idverifier() As Integer
        Using sqlconnection As New MySqlConnection(cnString)
            sqlconnection.Open()
            Dim sqlcommand As New MySqlCommand("Select COUNT(*) FROM tbl_account WHERE shd_agent = 'JONATHANT'")
            Return sqlcommand.ExecuteScalar()
            sqlconnection.Close()
        End Using
    End Function
End Class

推荐答案

您的查询应如下所示:

Your query should looks like:
SELECT COUNT(*)
FROM tbl_account
WHERE shd_agent LIKE 'JONA%'



以上查询数据: JONATHAN,JONAHTAN,JONATTHA 等。



如果你想得到完全匹配:


Above query mathes: JONATHAN, JONAHTAN, JONATTHA, etc.

If you want to get exact match:

SELECT COUNT(*)
FROM tbl_account
WHERE shd_agent = 'JONATHAN'





见这里:

http://dev.mysql.com/doc/refman/5.0/en/pattern- matching.html [ ^ ]


Hi Maciej Los,



我已经解决了!谢谢你的帮助。我使用此代码而不是使用函数。



Hi Maciej Los,

I've solved it! thanks for your help. I use this code instead of using function.

Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click

        Dim con As New MySqlConnection(cnString)
        con.Open()
        Dim cmd As New MySqlCommand("Select Count(*) from tbl_account where shd_agent = 'JONATHAN' ", con)
        Dim i As Integer = cmd.ExecuteScalar()
        cmd = Nothing
        con.Close()
        txt_count.Text = i

End Sub


已经有一个解决方案,但这里有一个替代感兴趣的人;



在DataGridView和MySQLTable中记录计数,并将它们相互比较。我认为它会很有用。



http://koraykaraman.com/koray/software/vb-net/record-count-mysql-vb-net.html [ ^ ]



Koray
There is already a solution but, here is an alternative one for interested people;

Record count in DataGridView and MySQLTable, comparing them with each other. I think it will be useful.

http://koraykaraman.com/koray/software/vb-net/record-count-mysql-vb-net.html[^]

Koray


这篇关于使用vb.net 2010在mysql中记录计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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