Thursday, 9 February 2017

Regular Expression Validator for email in VB.NET or ASP.NET

Dear All.

For email validation place range validator in the user form and edit the code with the given 'ValidationExpression" as  below.

<asp:RegularExpressionValidator ID="validateEmail"    
  runat="server" ErrorMessage="Invalid email."
  ControlToValidate="txtEmail" 
  ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" />
 
 
All the best.
 
 

Friday, 20 January 2017

Insert into table in Database

Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Public constr As String
    Public ds As New DataSet()
    Public da As SqlClient.SqlDataAdapter
    Public mySqlConn1 As New SqlClient.SqlConnection(constr)
    Public sql, sql1, code, asd, type, cartno As String


    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
        Dim conn As New SqlConnection
        Dim constr As String
        constr = "Data Source=.\SQLEXPRESS;AttachDbFilename=d:\Website2\App_Data\reg.mdf;Integrated Security=true;User Instance=true"

        conn.ConnectionString = constr
        conn.Open()
        sql = "insert into userreg values('Raju','10','Kollam','Raj bhavan','90909090','Govt')"

        Dim comm As New SqlCommand(sql, conn)
        comm.ExecuteNonQuery()
        
        conn.Close()
    End Sub
End Class

Machine Learning in Matlab

HI All,
Machine learning is an important concept to equip a program to classify data or predict some missing values.
For this purpose we use classifiers like
1. ANN
2. SVM
3. Naive Bayes etc


Matlab Exercise 1 - Arrays

Hi all,

Use the below url for the topics mentioned.

https://www.cs.cmu.edu/~ggordon/10601/recitations/matlab/pretty_matlab_pres.pdf

1. Arrays
2. If
3. Loop
4. Matrix
5. Functions

Tuesday, 10 January 2017

Client Side Validation of Text boxes in VB.NET

Hi All
Validation is very important in user input screen (HTML forms), because invalid data may get entered while inputting.
For example the age should be between 20 and 25, name shouldn't be left blank, email validation etc.

Let me show you how to set these conditions on a text. You can try the same on multiple textboxes.

Let me guide you through a few screen shots.

Step 1. Design the screen first with text box.




See the validation area which is highlighted.

For each textbox drag the required validation items near the textboxes.

At first I am placing the 'Required Field Validator' near Name text box and 'Range validator' for age (To set age range between 20 and 30)



Now we are going to connect the validators with the concerned text boxes. For this we should select that validator and right click to see the properties.






See the 'Control to Validate' option in the properties. There you select 'TextBox1', which is the name.

You can change the Message to be shown using the 'Error Message' property from the same list.




You repeat the same for Age also. There in the property list you can find 'Minimum Value' and 'Maximum Value' properties to set the range.


Try this and put your feedback.
All the best.

Tuesday, 27 December 2016

Log to multiple home pages - vb.net program

Imports System.Data
Imports System.Data.SqlClient
Partial Class login
    Inherits System.Web.UI.Page
    Public constr As String
    Public ds As New DataSet()
    Public da As SqlClient.SqlDataAdapter
    Public mySqlConn1 As New SqlClient.SqlConnection(constr)
    Public sql, sql1, code, asd, type, cartno As String
    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim conn As New SqlConnection
        Dim constr As String
        constr = "Data Source=.\SQLEXPRESS;AttachDbFilename=c:\citypilot\App_Data\regdb.mdf;Integrated Security=true;User Instance=true"

        conn.ConnectionString = constr
        conn.Open()
        sql = "select * from log where user_id='" & Login1.UserName.ToString & "' and password='" & Login1.Password.ToString & "'"

        Dim comm As New SqlCommand(sql, conn)

        Dim type As String

        Dim dr As SqlDataReader
        dr = comm.ExecuteReader
        Dim a As Integer
        If dr.Read() = True Then
            a = 1
            type = dr.GetString(2)
        Else

            a = 0
        End If
        dr.Close()
   
     

        If a = 1 Then
            Session("Userid") = Login1.UserName.ToString
           
            If (String.Compare(type.Trim(), "business") = 0) Then
                Response.Redirect("hupdate.aspx")
            ElseIf (String.Compare(type.Trim(), "Emergency") = 0) Then
                Response.Redirect("jupdate.aspx")
            End If

        Else
            MsgBox("Enter Valid User Name and Password!")

        End If
        conn.Close()
    End Sub
End Class

Thursday, 8 December 2016

Select an item from grid and store in a text box

Hi
It is very important to select an item from data grid and show that in a text box. This us  common in sales, purchase etc
See the new items in gridview for this activity highlighted in blue.
-------------------------------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default5.aspx.vb" Inherits="Default5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome to Admin Home
    </div>

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1"
        selectedindex="1"
       onselectedindexchanged="GridView2_SelectedIndexChanged"
       onselectedindexchanging="GridView2_SelectedIndexChanging"  >
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Rollno" HeaderText="Rollno"
                SortExpression="Rollno" />
           <asp:ImageField DataImageUrlField="filepath" ControlStyle-Width="100"
        ControlStyle-Height = "100" HeaderText = "Preview Image"/>
         <asp:ButtonField Text="Click" CommandName="Select" ItemStyle-Width="30"  />

        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [Name], [Rollno], [filepath] FROM [tblReg]" >
        </asp:SqlDataSource>
 
    <asp:TextBox ID="hupitem" runat="server"></asp:TextBox>
    <br />
 
    </form>
</body>
</html>

--------------------------------------------------------Code -------------------------

Partial Class Default5
    Inherits System.Web.UI.Page

    Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
        hupitem.Text = GridView2.SelectedRow.Cells(1).Text
    End Sub

    Protected Sub GridView2_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView2.SelectedIndexChanging
        hupitem.Text = GridView2.SelectedRow.Cells(1).Text
    End Sub
End Class

---------------------------------------------------------Screen--------------------------------------