.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get the data from sql server database

Posted By:laptop charles       Posted Date: July 25, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Select the data and get it and display in textbox.

*Create the data base using sql server.
*Firstname and LastName
*Copy the bellow coding then run.
*It contain two textbox and two label.
*The text box name is txt1 and txt2.
*Then give the connection string.
*Database name is "charles",table name is "charl".
*My server name is "ANONYMOUS".
*Will display the data on this textbox.

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim dr As SqlDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New SqlConnection("server=ANONYMOUS;Trusted_Connection=yes;database=charles")
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        cmd = New SqlCommand("select * from charl", con)
        dr = cmd.ExecuteReader

        While dr.Read()
            txt1.Text = dr(0)
            txt2.Text = dr(1)

        End While
    End Sub
End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend