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