Display Database sql server into label.text in vb,net 2010

Oct 9 2012 3:28 AM
"im stress when im doing this programming.. the code cant be run i dont know where's problem.. please help me guys solve this problem.. i need help"

my database name : Nama
table: ID, name, address, state, status


FORM1

 Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeOfDay
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = Nothing Then
            Form2.Show()
            Form2.Button1.Enabled = True
            Form2.Enabled = False
        Else
            Form2.Show()
            Form2.Enabled = True
        End If
    End Sub
End Class




 FORM 2

Imports System.Data.SqlClient
Public Class Form2
    Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dr As SqlDataReader
    Dim dt As DataSet
    Dim str As String

 

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim data As New DataSet
        lblID.Text = Form1.TextBox1.Text
        Label1.Text = Form1.Label1.Text

        If lblID.Text = "" Then Exit Sub



        If lblID.Text = Form1.TextBox1.Text Then


Else
            con.Open()
            str = " SELECT name, address, state, status FROM Nama WHERE ID = '" & lblID.Text & "'"
            da = New SqlDataAdapter(str, con)
            da.Fill(data, " Nama")
          

            lblnama.DataBindings.Add("text", data, "Nama.name")
            lbladdress.DataBindings.Add("text", data, "Nama.address")
            lblstate.DataBindings.Add("text", data, "Nama.state")
            lblstatus.DataBindings.Add("text", data, "Nama.status")
        End If

    End Sub


this my Example Project that cant run

Form1



Form2





please help me :(... sorry my english so weak.. hope u'll understand what i means ^^

Answers (2)