Saturday, June 22, 2013

Geeting Values into TextBox From Table VB.NET

  Dim dr As SqlDataReader
        Dim cn As New SqlConnection
        Dim cmd As New SqlCommand
        cn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        cn.Open()
        cmd.Connection = cn
        cmd.CommandText = "SELECT mainname,maincontactperson,mainbillingaddress, mainbillingpincode,maincorraddress FROM mainmaster WHERE mainname = @mainname"

        cmd.Parameters.Add(New SqlParameter("@mainname", (ddlistcustomername.Text)))
        dr = cmd.ExecuteReader()
        If (dr.Read()) Then
            txtname.Text = dr(0)
            txtcperson.Text = dr(1)
            txtbaddress.Text = dr(2)
            txtbapincode.Text = dr(3)
            txtcaddress.Text = dr(4)
            txtcapincode.Text = dr(5)
                      cn.Close()
        End If

No comments: