如何在vb中的文本框中显示数据sql [英] how to display data sql in text box in vb

查看:134
本文介绍了如何在vb中的文本框中显示数据sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚学习Visual Basic

  现在我有一个项目,我无法向我显示我的数据库信息

请指示我

I'm just learning Visual Basic
  Now I have a project and I can not display my database information with me
please direct me

  Private Sub okbtn_Click(sender As Object,e As EventArgs)处理okbtn.Click

        con = New SqlConnection

        con.ConnectionString =(" Data Source = FARAHANI-PC; Initial Catalog = pc_info; Integrated Security = True")

        Dim dadapter As New SqlDataAdapter

       尝试

            con.Open()

            Dim Query As String

           查询=" select * from  [dbo]。[SYS-INFO]其中[system num] ='" &安培; sysnotxtbox.Text.ToString& "'"

            cmd =新的SqlCommand(查询,骗局)

            Dim reader As SqlDataReader

            reader = cmd.ExecuteReader

            Dim count As Integer



           读者阅读。阅读。



           结束时


           如果count = 1则为


                 ; OSTETXBOX.Text = reader.GetInt16(" os")



             ; ElseIf count> 1然后

                MessageBox.Show(QUOT;شمارهسیستمراواردکنید")



          &NBSP ;否则b $ b                MessageBox.Show(QUOT;شمارهواردشدهدرلیستموجونمیباشد")

           结束如果

            conn.Close()




        Catch ex As SqlException

            MessageBox.Show(ex.Message)

       最后是
       结束尝试

  Private Sub okbtn_Click(sender As Object, e As EventArgs) Handles okbtn.Click
        con = New SqlConnection
        con.ConnectionString = ("Data Source=FARAHANI-PC;Initial Catalog=pc_info;Integrated Security=True")
        Dim dadapter As New SqlDataAdapter
        Try
            con.Open()
            Dim Query As String
            Query = "select * from  [dbo].[SYS-INFO] where [system num]='" & sysnotxtbox.Text.ToString & "' "
            cmd = New SqlCommand(Query, con)
            Dim reader As SqlDataReader
            reader = cmd.ExecuteReader
            Dim count As Integer

            While reader.Read


            End While

            If count = 1 Then

                OSTETXBOX.Text = reader.GetInt16("os")

            ElseIf count > 1 Then
                MessageBox.Show("شماره سیستم را وارد کنید")

            Else
                MessageBox.Show("شماره وارد شده در لیست موجو نمیباشد")
            End If
            conn.Close()


        Catch ex As SqlException
            MessageBox.Show(ex.Message)
        Finally
        End Try

推荐答案

最快捷的方式以及我们网站上的参数。

The quickest way and also with parameters on our website.

http://www.vb-tips.com/ExecuteScalarText.ASPX


这篇关于如何在vb中的文本框中显示数据sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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