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--------------------------------------



Showing uploaded images in data grid using vb.net

Hi all,

See the code below. Important code is highlighted in blue.
-----------------------------------------

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

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome to Admin Home
    </div>
 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [Name], [Rollno], [filepath] FROM [tblReg]" >
        </asp:SqlDataSource>
 
    <br />
    <br />
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1">
        <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"/>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
    <br />
    </form>
</body>
</html>


Table structure and sample data




Tuesday, 29 November 2016

Advanced indexing techniques used in warehouses..

Hi All,

Traditional access methods are b-trees, hash tables and grid files (lot more..)

Inverted indexes (lists), bit map indexed and join indexes are common in warehouses.

Block your website from search engine indexing

Hi All,

It is a common question asked from web administrators.
Use robots.txt file in your root folder of website/webserver

robots.txt


Web site admins use the /robots.txt file to follow instructions about their website to web robots; this is known as The Robots Exclusion Protocol.

It works likes this: a robot wants to visit a Web site URL, say http://www.abc.com/welcome.html. Before it does so, it firsts checks for http://www.abc.com/robots.txt, and finds:

User-agent: *
Disallow: /

When the search engine encounter such a line, the indexing will be stopped.

Friday, 25 November 2016

How to Upload a file using VB.NET

Hi All,

It is very important to upload file to specific folders in Server.
At first you design one page with a FileUpload control, Label Control and Button Control as given below

Main.aspx

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

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome to Admin Home
    </div>

 
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Upload" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <br />
    </form>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------
As a next step click the Button Control and add the code in the Main.aspx.vb file

Main.aspx.vb


Partial Class Main
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
     
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If FileUpload1.HasFile Then
            Try
                FileUpload1.SaveAs("C:\HUPUploads\" & _
                    FileUpload1.FileName)
                Label1.Text = "File name: " & _
                    FileUpload1.PostedFile.FileName & "<br>" & _
                    "File Size: " & _
                    FileUpload1.PostedFile.ContentLength & "<br>" & _
                    "Content type: " & _
                    FileUpload1.PostedFile.ContentType & "<br>" & _
                    "Location Saved: C:\Uploads\" & _
                    FileUpload1.FileName
            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
            End Try
        Else
            Label1.Text = "You have not specified a file."
        End If
    End Sub
End Class


---------------------------------------------------------------------------------------------------------------------
NB: Make sure that you have a folder in C drive as "HUPUploads"




Saturday, 19 November 2016

UpdateCommand in VB.NET

Hi All,
See the code for UpdateCommand. This is almost similar to Delete command.
If you have more fields in the table to update then the UpdateCommand in the code will look like
  UpdateCommand="UPDATE HUPTable SET HUPPass = @HUPPass,HUPAddress=@HUPAddress WHERE HUPName = @HUPName"

Code starts here
---------------------------------------------------------------------------------

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

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome to Admin Home
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1" DataKeyNames="HUPName">
        <Columns>
            <asp:BoundField DataField="HUPName" HeaderText="HUPName"
                SortExpression="HUPName" />
            <asp:BoundField DataField="HUPPass" HeaderText="HUPPass"
                SortExpression="HUPPass" />
            <asp:CommandField ShowDeleteButton="True" />
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        UpdateCommand="UPDATE HUPTable SET HUPPass = @HUPPass WHERE HUPName = @HUPName"
        SelectCommand="SELECT [HUPName],[HUPPass] FROM [HUPTable]"
        DeleteCommand="Delete from HUPTable where HUPName=@HUPName" >
        <DeleteParameters>
                <asp:Parameter Name="HUPName" Type="String" />
                 <asp:Parameter Name="HUPPass" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="HUPName" Type="String" />
                 <asp:Parameter Name="HUPPass" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>

Friday, 18 November 2016

Change SelectCommand during Runtime in VB.NET

Hi All,

If you want to Change SelectCommand during Runtime in VB.NET use the code below in the page where the grid is placed.

Partial Class Main
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim qrystring As String
        qrystring = "U"
       
        SqlDataSource1.SelectCommand = "SELECT [HUPName],[HUPPass] FROM                   
        [HUPTable] where HUPName like '%" & qrystring & "%'"
     
        GridView1.DataBind()
    
    End Sub
End Class


Saturday, 5 November 2016

Process combo box

Hi all,
To retrive the content of a combo box use the code below in VB.NET




dim gender as string

gender=cboname.selectedItem.value

Friday, 14 October 2016

5. Design a form and Save data to the Login Table

Hi,
This is very important, that using this option we can design a form and the data can be save to database without going to the Database view.

At first add a web form , come to the design view and drag and HTML table



After that type Name and Password in the first column and then adjust the column width


Adjusting column width


The add Button and Text box
from Tool Box

Adding Button

Change ID of name and password text box


See the properties box in the right side for changing ID


give name as txtName and password as txtPassword


Double click the button add code


The place to copy the code












Copy the code in Blue to your button click function. The Red code change according to your folder path and table name.

Imports System.Data
Imports System.Data.SqlClient
Partial Class Default4
    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 Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim conn As New SqlConnection
        Dim constr As String
        constr = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project1\App_Data\Database.mdf;Integrated Security=true;User Instance=true"

        conn.ConnectionString = constr
        conn.Open()
        sql = "insert into table1 values('" & txtName.Text & "','" & txtPassword.Text & "')"

        Dim comm As New SqlCommand(sql, conn)



        Dim i As Integer
        i = comm.ExecuteNonQuery()


        MsgBox("Data saved")

        conn.Close()
    End Sub
End Class

Tuesday, 11 October 2016

4. Delete Update command in Data Grid [ VB Dot Net, VB.NET]

Hi All,

It is too easy to incorporate delete and update options with the Data Grid.

Use the Code below [ Design View]. Important parts are highlighted in Blue.


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

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome to Admin Home
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1" DataKeyNames="HUPName">
        <Columns>
            <asp:BoundField DataField="HUPName" HeaderText="HUPName"
                SortExpression="HUPName" />
            <asp:BoundField DataField="HUPPass" HeaderText="HUPPass"
                SortExpression="HUPPass" />
            <asp:CommandField ShowDeleteButton="True" />
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [HUPName],[HUPPass] FROM [HUPTable]" DeleteCommand="Delete from HUPTable where HUPName=@HUPName" >
        <DeleteParameters>
                <asp:Parameter Name="HUPName" Type="String" />
                 <asp:Parameter Name="HUPPass" Type="String" />
            </DeleteParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>

Saturday, 8 October 2016

3. View Table Data In Form Using Data Grid

1. This helps you to connect your table to a Data Grid which will show the data in your form

a. At first you add a new Web form 'ViewData.aspx' Using the Website Menu

 Add a web form

After adding the form come to the design view.


 Come to the Data Tool Box and select GridView


 Drag Grid to this point


 Click the Small circle and Select the options









Now Press Next and Finish.
Now Run the page and view the data in the Grid.

2. Login and Database code in VB.NET (VBDOTNET)

1. Default.aspx (First Page created by IDE)



Here in this figure not the name of the file (Default.aspx) and Source and Design Items.
Currently the ' Source' tab is enabled.

See the effect of 'Design Tab'


2. Now We are going to include 'Login' tool here.

Here see the 'Tool Box' option in the left side
and Select 'Login' option and see the 'Login tool' . Drag this tool to your design



See the Dragged 'Login Tool'. So we can save a lot of time typing and designing the Login Box which contains username and password options.


See the line 'Type the Code here' .
At that place we should write the code.

The new class will look like [Code to be copied are highlighted in Blue for convenience]

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 Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        'Type the code here.
   
        Dim conn As New SqlConnection
        Dim constr As String
        constr = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\AUM HUP C#\HUPEGov\App_Data\Database.mdf;Integrated Security=true;User Instance=true"

        conn.ConnectionString = constr
        conn.Open()
        sql = "select * from HUPTable where HUPName='" & Login1.UserName.ToString & "' and HUPPass='" & Login1.Password.ToString & "'"

        Dim comm As New SqlCommand(sql, conn)



        Dim dr As SqlDataReader
        dr = comm.ExecuteReader
        Dim a
        If dr.Read() = True Then
            a = 1
        Else
            a = 0
        End If
        dr.Close()
        If a = 1 Then
            Session("Userid") = Login1.UserName.ToString
            'sql = "delete cart where uname='" & Session("Userid") & "'"
            'Dim cmd As New SqlCommand(sql, conn)
            'cmd.ExecuteNonQuery()
            Response.Redirect("Main.aspx")
        Else
            MsgBox("Enter Valid User Name and Password!")

        End If
        conn.Close()
    End Sub
End Class


NB: The path of Database will change according to your settings.

Also Add a new Form 'Main.aspx'



3. Creation of Database 

Follow the given options



See the Database Tab in the given figure below


Here Right click the Table and select 'Add New Table'


Give a suitable Name to the Table


As the next step we are going to add a record in the table.
So go to the 'Database Tab' and Expand the Table Option and Select the HUPTable
Right Click the Table and select 'Show Table Data' and type the username as 'HUP' and password as 'HUPA' and save.


Friday, 7 October 2016

1. Introduction

Hi All,
Welcome to my VB.NET Blog.
I assure you all a nice study. You will get the confidence to create your own projects and Web Applications.

1. VB.NET IDE


From Here we will start our Project Development.

2. Create a new Web Site


3. Save this Project with Language VB.NET and in a particular Project Folder