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