2 Replies - 213 Views - Last Post: 05 December 2017 - 06:48 PM Rate Topic: -----

#1 micro1111  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-November 17

how to fetch data from Sql server using vb.net?

Posted 04 December 2017 - 08:14 PM

Hi! I was wondering how I can fetch my data from my database(SQLServer2014) using vb.net(VS2012). Below is the code I ended up doing. Thanks for your help!




 Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer7.Tick
        Timer7.Interval = 5000
        Timer7.Enabled = True
        Dim scn As New SqlConnection
        Dim scm As New SqlCommand
        Dim str1 As String
        Dim reader As SqlDataReader = scm.ExecuteReader
        scn.Open()
        Try
            str1 = "Server=servername;Database=dbname;User Id=id;Password=password;"
            scn.ConnectionString = str1
            scm.Connection = scn

            scm.CommandText = "SELECT * from ConCon"
            scm.ExecuteNonQuery()
            scm.CommandText = "SELECT * from AppCon"
            scm.ExecuteNonQuery()
            scm.CommandText = "SELECT * from PrioCon"
            scm.ExecuteNonQuery()
            scm.CommandText = "SELECT * from RetCon"
            scm.ExecuteNonQuery()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        Label1.Text = reader.ToString("ConNumber")
        Label18.Text = reader.ToString("ConCounter")

        scn.Close()
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: how to fetch data from Sql server using vb.net?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13659
  • View blog
  • Posts: 54,529
  • Joined: 12-June 08

Re: how to fetch data from Sql server using vb.net?

Posted 05 December 2017 - 03:41 AM

Why would a timer be involved?

Basic CRUD formatting:
http://www.dreaminco...-adapter-setup/
http://www.dreaminco...-command-setup/
Was This Post Helpful? 0
  • +
  • -

#3 micro1111  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-November 17

Re: how to fetch data from Sql server using vb.net?

Posted 05 December 2017 - 06:48 PM

Hi! Thanks for replying. I wrote the code inside the timer so for every time the timer ticks it could fetch the latest data from each table to display them on the form using label.text.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1