Thursday, June 27, 2013

Validate TextBox For Digits and Texts VB.NET


imports System.Text.RegularExpressions

 // For Text Only

 If Not Regex.Match(TextBox1.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
    MsgBox("Please enter text only.")
    TextBox1.Focus()
  End If


// For Digits Only 

 If Not Regex.Match(TextBox1.Text, "^[0-9]*$", RegexOptions.IgnoreCase).Success Then
    MsgBox("Please enter Digits only.")
    TextBox1.Focus()
  End If

Validate Email Through RegularExpressionValidator VB.NET

 <asp:RegularExpressionValidator ID="remail"
      runat="server"
      ControlToValidate="txtemail" ErrorMessage="Enter your email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>

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