Simple ASP Practicals& Java Exercise
Simple ASP Practicals& Java Exercise
CODING:
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server" ControlToValidate="TextBox1"ErrorMessage="enter correct value" style="z-index: 1; left: 178px; top: 34px; position: absolute; height: 26px"></asp:RequiredFieldValidator>
OUTPUT:
CODING:
<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server" ControlToValidate="TextBox1"ErrorMessage="RegularExpressionValidator" style="z-index: 1; left: 30px; top: 173px; position: absolute" ValidationExpression="p[0-9]{4}">enter correct value</asp:RegularExpressionValidator>
OUTPUT:
CODING:
<asp:CompareValidatorID="CompareValidator1"runat="server" ControlToCompare="TextBox2"ControlToValidate="TextBox1" ErrorMessage="CompareValidator"Operator="GreaterThan" style="z-index: 1; left: 346px; top: 55px; position: absolute"Type="Date">end date must be greater than start date</asp:CompareValidator>
OUTPUT:
10
CODING:
<asp:RangeValidatorID="RangeValidator1"runat="server" ControlToValidate="TextBox1"ErrorMessage="RangeValidator"MaximumValue="100" MinimumValue="0"style="z-index: 1; left: 64px; top: 132px; position: absolute" Type="Integer">enter value between 0 to 100</asp:RangeValidator>
11
OUTPUT:
12
13
CODING:
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server" ControlToValidate="TextBox1"ErrorMessage="RequiredFieldValidator" style="z-index: 1; left: 345px; top: 79px; position: absolute">enter user id</asp:RequiredFieldValidator> <asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server" ControlToValidate="TextBox2"ErrorMessage="RequiredFieldValidator" style="z-index: 1; left: 348px; top: 147px; position: absolute">enter password</asp:RequiredFieldValidator> <asp:ValidationSummaryID="ValidationSummary1"runat="server" HeaderText="list of errors in the page"ShowMessageBox="True" style="z-index: 1; left: 35px; top: 231px; position: absolute; height: 38px; width: 1249px"/>
14
OUTPUT:
15
16
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp2", con) dr = cmd.ExecuteReader DataGrid1.DataSource = dr DataGrid1.DataBind() con.Close() EndSub
17
OUTPUT:
18
19
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button2_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button2.Click con.Open() cmd = NewSqlCommand("insert into emp2 values(3, 'britto', 30000)", con) cmd.ExecuteNonQuery() con.Close() EndSub
20
OUTPUT:
21
22
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button4_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button4.Click con.Open() cmd = NewSqlCommand("delete from emp2", con) cmd.ExecuteNonQuery() con.Close() EndSub EndClass
23
OUTPUT:
24
25
26
OUTPUT:
27
EX 3A: DATA MANIPULATION OPERATORS IN CONNECTIVITY ENVIRONMENT USING PARAMETERS SELECT OPERATION: DESIGN:
28
CODING: Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) dr = cmd.ExecuteReader DataGrid1.DataSource = dr DataGrid1.DataBind() con.Close() EndSub
29
OUTPUT:
30
31
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button2_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button2.Click con.Open() cmd = NewSqlCommand("insert into emp3 values(@x, @y, @z, @a)", con) cmd.Parameters.AddWithValue("@x", Val(TextBox1.Text)) cmd.Parameters.AddWithValue("@y", (TextBox2.Text)) cmd.Parameters.AddWithValue("@z", Val(TextBox3.Text)) cmd.Parameters.AddWithValue("@a", Val(TextBox4.Text)) cmd.ExecuteNonQuery() con.Close() EndSub
32
OUTPUT:
33
34
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button3_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button3.Click con.Open() cmd = NewSqlCommand("update emp3 set sal=@s where depno=@d", con) cmd.Parameters.AddWithValue("@s", Val(TextBox3.Text)) cmd.Parameters.AddWithValue("@d", Val(TextBox4.Text)) cmd.ExecuteNonQuery() con.Close() EndSub EndClass
35
OUTPUT:
36
37
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button4_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button4.Click con.Open() cmd = NewSqlCommand("delete from emp3 where depno=@p", con) cmd.Parameters.AddWithValue("@p", Val(TextBox4.Text)) cmd.ExecuteNonQuery() con.Close() EndSub
38
OUTPUT:
39
40
SQL QUERY:
createprocedure [dbo].[p1] ( @x asinteger, @y asvarchar(20), @z asinteger, @a asinteger )as insertinto emp3 values(@x, @y, @z, @a)
41
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("p1", con) cmd.CommandType = Data.CommandType.StoredProcedure cmd.Parameters.AddWithValue("@x", Val(TextBox1.Text)) cmd.Parameters.AddWithValue("@y", (TextBox2.Text)) cmd.Parameters.AddWithValue("@z", Val(TextBox3.Text)) cmd.Parameters.AddWithValue("@a", Val(TextBox4.Text)) cmd.ExecuteNonQuery() con.Close() EndSub ProtectedSub Button2_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button2.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) dr = cmd.ExecuteReader DataGrid1.DataSource = dr DataGrid1.DataBind() con.Close() EndSub EndClass
42
OUTPUT:
43
44
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) Repeater1.DataSource = cmd.ExecuteReader Repeater1.DataBind() con.Close() EndSub EndClass
45
HTML CODING:
<asp:RepeaterID="Repeater1"runat="server"> <HeaderTemplate> <tableborder="3"> <tr> <th>employee no</th> <th>employee name</th> <th>salary</th> <th>department</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Container.DataItem("eno")%></td> <td><%# Container.DataItem("name")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
46
OUTPUT:
47
48
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DropDownList1.DataSource = cmd.ExecuteReader DropDownList1.DataTextField = "eno" DropDownList1.DataBind() con.Close() EndSub EndClass
49
OUTPUT:
50
51
CODING:
Imports System.Data.SqlClient PartialClassDefault3 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) RadioButtonList1.DataSource = cmd.ExecuteReader RadioButtonList1.DataTextField = "name" RadioButtonList1.DataBind() con.Close() EndSub EndClass
52
OUTPUT:
53
54
CODING:
Imports System.Data.SqlClient PartialClassDefault4 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) CheckBoxList1.DataSource = cmd.ExecuteReader CheckBoxList1.DataTextField = "sal" CheckBoxList1.DataBind() con.Close() EndSub EndClass
55
OUTPUT:
56
57
CODING:
Imports System.Data.SqlClient PartialClassDefault5 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) ListBox1.DataSource = cmd.ExecuteReader ListBox1.DataTextField = "depno" ListBox1.DataBind() con.Close() EndSub EndClass
58
OUTPUT:
59
60
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataList1.DataSource = cmd.ExecuteReader DataList1.DataBind() con.Close() EndSub EndClass
61
HTML CODING:
<asp:DataListID="DataList1"runat="server" style="z-index: 1; left: 10px; top: 34px; position: absolute; height: 57px; width: 346px"> <ItemTemplate> <table> <tr> <td>employeeno</td> <td><%# Container.DataItem("eno")%></td> </tr> <tr> <td>employee name</td> <td><%# Container.DataItem("name")%></td> </tr> </table> </ItemTemplate> <SeparatorTemplate><hr/></SeparatorTemplate> </asp:DataList>
62
OUTPUT:
63
64
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault3 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataList1.DataSource = cmd.ExecuteReader DataList1.DataBind() con.Close() EndSub EndClass
65
HTML CODING:
<asp:DataListID="DataList1"CellSpacing="20"CellPadding="10"ItemStyleBorderStyle="Dashed"AlternatingItemStyle-BackColor="Pink"ItemStyle-FontBold="true"AlternatingItemStyle-ForeColor="Blue"ItemStyle-FontNames="Arial"AlternatingItemStyle-Font-Size="10"runat="server"> <ItemTemplate> <%# Container.DataItem("name")%> </ItemTemplate> </asp:DataList>
66
OUTPUT:
67
68
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault4 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataList1.DataSource = cmd.ExecuteReader DataList1.DataBind() con.Close() EndSub EndClass
69
HTML CODING:
<asp:DataListID="DataList1"runat="server"> <HeaderTemplate> <h2>employee database with salary</h2> </HeaderTemplate> <ItemTemplate> <table> <tr> <td>employee no</td> <td><%# Container.DataItem("eno")%></td> </tr> <tr> <td>employee name</td> <td><%# Container.DataItem("name")%></td> </tr> <tr> <td>salary</td> <td><%# Container.DataItem("sal")%></td> </tr> </table> </ItemTemplate> <SeparatorTemplate><hr/></SeparatorTemplate> <FooterTemplate><h6>the above are the details of employee database</h6></FooterTemplate> </asp:DataList>
70
OUTPUT:
71
EX 7A: DESIGN:
72
CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp2", con) dr = cmd.ExecuteReader DataGrid1.DataSource = dr DataGrid1.DataBind() con.Close() EndSub
73
OUTPUT:
74
75
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() con.Close() EndSub EndClass
76
HTML CODING:
<asp:DataGridID="DataGrid1"runat="server"> <Columns> <asp:BoundColumnDataField="eno"/> <asp:BoundColumnDataField="name"/> </Columns> </asp:DataGrid>
77
OUTPUT:
78
79
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault3 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" con.Open() cmd = NewSqlCommand("select * from emp3", con) DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() con.Close() EndSub EndClass
80
HTML CODING:
<asp:DataGridID="DataGrid1"AutoGenerateColumns="false"runat="server" style="z-index: 1; left: 34px; top: 155px; position: absolute; height: 133px; width: 175px"> <Columns> <asp:BoundColumnDataField="eno"HeaderText="emp no"/> <asp:HyperLinkColumnDataTextField="name"NavigateUrl="name"DataNavigateUrlField="name" /> </Columns> </asp:DataGrid>
81
OUTPUT:
82
83
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault4 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() con.Close() EndSub EndClass
84
HTML CODING:
<asp:DataGridID="DataGrid1"AutoGenerateColumns="false"runat="server" style="z-index: 1; left: 319px; top: 125px; position: absolute; height: 133px; width: 175px"> <Columns> <asp:BoundColumnDataField="eno"HeaderText="emp no"/> <asp:TemplateColumn> <ItemTemplate> <tableborder="3"> <tr> <td>employee name</td> <td><%# Container.DataItem("name")%></td> </tr> <tr> <td>salary</td> <td><%# Container.DataItem("sal")%></td> </tr> </table> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>
85
OUTPUT:
86
87
.NET CODING:
Imports System.Data.SqlClient PartialClassDefault5 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim dr AsSqlDataReader ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp3", con) DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() con.Close() EndSub ProtectedSub DataGrid1_ItemCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandName = "select"Then e.Item.BackColor = System.Drawing.Color.SaddleBrown e.Item.Font.Bold = True Else e.Item.BackColor = System.Drawing.Color.SeaGreen e.Item.Font.Bold = False EndIf EndSub EndClass
88
HTML CODING:
<asp:DataGridID="DataGrid1"runat="server" style="z-index: 1; left: 429px; top: 127px; position: absolute; height: 133px; width: 175px"> <Columns> <asp:BoundColumnDataField="eno"HeaderText="emp no"/> <asp:ButtonColumnCommandName="select"Text="select"/> <asp:ButtonColumnCommandName="unselect"Text="unselect"/> </Columns> </asp:DataGrid>
89
OUTPUT:
90
91
HTML CODING:
<asp:SqlDataSourceID="SqlDataSource1"runat="server" ConnectionString="<%$ ConnectionStrings:dbaseConnectionString %>" DeleteCommand="DELETE FROM [emp3] WHERE [id] = @id" InsertCommand="INSERT INTO [emp3] ([id], [name], [sal]) VALUES (@id, @name, @sal)" SelectCommand="SELECT * FROM [emp3]" UpdateCommand="UPDATE [emp3] SET [name] = @name, [sal] = @sal WHERE [id] = @id"> <DeleteParameters> <asp:ParameterName="id"Type="Int32"/> </DeleteParameters> <InsertParameters> <asp:ParameterName="id"Type="Int32"/> <asp:ParameterName="name"Type="String"/> <asp:ParameterName="sal"Type="Int32"/> </InsertParameters> <UpdateParameters> <asp:ParameterName="name"Type="String"/> <asp:ParameterName="sal"Type="Int32"/> <asp:ParameterName="id"Type="Int32"/> </UpdateParameters> </asp:SqlDataSource> <asp:DataGridID="DataGrid1"runat="server"AllowPaging="True" AllowSorting="True"AutoGenerateColumns="False"DataKeyNames="id" DataSourceID="SqlDataSource1" style="z-index: 1; left: 572px; top: 121px; position: absolute; height: 133px; width: 187px"> <Columns> <asp:CommandFieldShowDeleteButton="True"ShowEditButton="True" ShowSelectButton="True"/> <asp:BoundFieldDataField="id"HeaderText="id"ReadOnly="True" SortExpression="id"/> <asp:BoundFieldDataField="name"HeaderText="name"SortExpression="name"/> <asp:BoundFieldDataField="sal"HeaderText="sal"SortExpression="sal"/> </Columns> </asp:DataGrid>
92
OUTPUT:
93
94
.NET CODING:
Imports System.Data PartialClassDefault2 Inherits System.Web.UI.Page ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click Dim dt AsDataTable Dim dc AsDataColumn Dim dr AsDataRow dt = NewDataTable("emp") dc = NewDataColumn("eno", GetType(Integer)) dt.Columns.Add(dc) dc = NewDataColumn("ename", GetType(String)) dt.Columns.Add(dc) dc = NewDataColumn("sal", GetType(Integer)) dc.DefaultValue = 1000 dt.Columns.Add(dc) dr = dt.NewRow dr("eno") = 1 dr("ename") = "yuvaraj" dr("sal") = 1000 dt.Rows.Add(dr) dr = dt.NewRow dr("eno") = 2 dr("ename") = "britto" dt.Rows.Add(dr) DataGrid1.DataSource = dt DataGrid1.DataBind() EndSub ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load EndSub EndClass
95
OUTPUT:
96
97
.NET CODING:
Imports System.Data PartialClassDefault3 Inherits System.Web.UI.Page ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click Dim dt AsDataTable Dim dc AsDataColumn Dim dr AsDataRow dt = NewDataTable("emp") dc = NewDataColumn("eno", GetType(Integer)) dc.Unique = True dt.Columns.Add(dc) dc = NewDataColumn("ename", GetType(String)) dt.Columns.Add(dc) dc = NewDataColumn("sal", GetType(Integer)) dc.DefaultValue = 1000 dt.Columns.Add(dc) dr = dt.NewRow dr("eno") = 1 dr("ename") = "vettri" dr("sal") = 1000 dt.Rows.Add(dr) dr = dt.NewRow dr("eno") = 2 dr("ename") = "siva" dt.Rows.Add(dr) DataGrid1.DataSource = dt DataGrid1.DataBind() EndSub EndClass
98
OUTPUT:
99
100
.NET CODING:
Imports System.Data PartialClassDefault4 Inherits System.Web.UI.Page ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click Dim dt AsDataTable Dim dc AsDataColumn Dim dr AsDataRow dt = NewDataTable("emp") dc = NewDataColumn("eno", GetType(Integer)) dc.AutoIncrement = True dc.AutoIncrementSeed = 100 dc.AutoIncrementStep = 1 dt.Columns.Add(dc) dc = NewDataColumn("ename", GetType(String)) dt.Columns.Add(dc) dc = NewDataColumn("sal", GetType(Integer)) dc.DefaultValue = 1000 dt.Columns.Add(dc) dr = dt.NewRow dr("ename") = "yuvaraj" dr("sal") = 10000 dt.Rows.Add(dr) dr = dt.NewRow dr("ename") = "vettri" dt.Rows.Add(dr) DataGrid1.DataSource = dt DataGrid1.DataBind() EndSub ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load EndSub EndClass
101
OUTPUT:
102
103
CODING:
Imports System.Data PartialClassDefault5 Inherits System.Web.UI.Page Dim dt AsDataTable Dim dc AsDataColumn Dim dr AsDataRow ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load dt = NewDataTable("emp") dc = NewDataColumn("eno", GetType(Integer)) dc.AutoIncrement = True dc.AutoIncrementSeed = 100 dc.AutoIncrementStep = 1 dt.Columns.Add(dc) dc = NewDataColumn("ename", GetType(String)) dt.Columns.Add(dc) dc = NewDataColumn("sal", GetType(Integer)) dc.DefaultValue = 1000 dt.Columns.Add(dc) dr = dt.NewRow dr("ename") = "britto" dr("sal") = 1000 dt.Rows.Add(dr) dr = dt.NewRow dr("ename") = "yuvaraj" dt.Rows.Add(dr) DataGrid1.DataSource = dt DataGrid1.DataBind() EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click dt.Rows(0).Delete() DataGrid2.DataSource = dt DataGrid2.DataBind() EndSub EndClass
104
OUTPUT:
105
106
Coding:
Imports System.Data.SqlClient Imports System.Data PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim da AsSqlDataAdapter Dim ds AsNewDataSet ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() ds = NewDataSet da = NewSqlDataAdapter("select * from emp", con) da.FillSchema(ds, SchemaType.Mapped, "emp") DataGrid1.DataSource = ds DataGrid1.DataBind() con.Close() EndSub EndClass
107
Output:
108
109
Coding:
Imports System.Data.SqlClient Imports System.Data PartialClassDefault3 Inherits System.Web.UI.Page Dim dt AsDataTable Dim dt1 AsDataTable Dim dc AsDataColumn Dim dr AsDataRow Dim ds AsNewDataSet ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load dt = NewDataTable("emp") dc = NewDataColumn("eno", GetType(Integer)) dc.Unique = True dt.Columns.Add(dc) dc = NewDataColumn("ename", GetType(String)) dt.Columns.Add(dc) dc = NewDataColumn("sal", GetType(Integer)) dt.Columns.Add(dc) dc = NewDataColumn("dno", GetType(Integer)) dt.Columns.Add(dc) dr = dt.NewRow dr("eno") = 1 dr("ename") = "yuvaraj" dr("sal") = 10000 dr("dno") = 10 dt.Rows.Add(dr) dr = dt.NewRow dr("eno") = 2 dr("ename") = "dinesh" dr("sal") = 20000 dr("dno") = 20 dt.Rows.Add(dr) DataGrid1.DataSource = dt DataGrid1.DataBind() dt1 = NewDataTable("dept") dc = NewDataColumn("dno", GetType(Integer)) dc.Unique = True dt1.Columns.Add(dc) dc = NewDataColumn("dname", GetType(String)) dt1.Columns.Add(dc) dr = dt1.NewRow dr("dno") = 10
110
dr("dname") = "yuvaraj" dt1.Rows.Add(dr) dr = dt1.NewRow dr("dno") = 20 dr("dname") = "dinesh" dt1.Rows.Add(dr) ds.Tables.Add(dt) ds.Tables.Add(dt1) DataGrid2.DataSource = dt1 DataGrid2.DataBind() ds.Relations.Add("xxx", ds.Tables("emp").Columns("dno"), ds.Tables("dept").Columns("dno")) DataGrid3.DataSource = ds DataGrid3.DataBind() EndSub EndClass
111
Output:
112
113
CODING: Imports System.Data Imports System.Data.SqlClient PartialClassDefault2 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim da AsSqlDataAdapter Dim ds AsNewDataSet Dim dv AsNewDataView ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = NewSqlCommand("select * from emp", con) da = NewSqlDataAdapter(cmd) da.Fill(ds, "emp") dv = ds.Tables("emp").DefaultView() DataGrid1.DataSource = dv DataGrid1.DataBind() con.Close() EndSub EndClass
114
Output:
115
116
CODING: Imports System.Data.SqlClient Imports System.Data PartialClassDefault3 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim da AsSqlDataAdapter Dim ds AsNewDataSet Dim dv AsNewDataView ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" con.Open() cmd = NewSqlCommand("select * from emp", con) da = NewSqlDataAdapter(cmd) da.Fill(ds, "emp") dv = ds.Tables("emp").DefaultView() DataGrid1.DataSource = dv DataGrid1.DataBind() con.Close() EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click dv.RowFilter = "eno=3" DataGrid1.DataSource = dv DataGrid1.DataBind() EndSub EndClass
117
Output:
118
119
CODING: Imports System.Data Imports System.Data.SqlClient PartialClassDefault4 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim da AsSqlDataAdapter Dim ds AsNewDataSet Dim dv AsNewDataView ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" con.Open() cmd = NewSqlCommand("select * from emp", con) da = NewSqlDataAdapter(cmd) da.Fill(ds, "emp") dv = ds.Tables("emp").DefaultView() DataGrid1.DataSource = dv DataGrid1.DataBind() con.Close() EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click dv.Sort = "eno desc" DataGrid1.DataSource = dv DataGrid1.DataBind() EndSub EndClass
120
Output:
121
122
Coding: Imports System.Data Imports System.Data.SqlClient PartialClassDefault5 Inherits System.Web.UI.Page Dim con AsNewSqlConnection Dim cmd AsSqlCommand Dim da AsSqlDataAdapter Dim ds AsNewDataSet Dim dv AsNewDataView ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load con.ConnectionString = "Data Source=.; Initial Catalog=dbase; uid=sa; pwd=123qwe" cmd = NewSqlCommand("select * from emp", con) da = NewSqlDataAdapter(cmd) da.Fill(ds, "emp") dv = ds.Tables("emp").DefaultView() DataGrid1.DataSource = dv DataGrid1.DataBind() con.Close() EndSub ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click Dim x AsObject Dim i AsInteger dv.Sort = "name" x = "vettri" i = dv.Find(x) If (i <> -1) Then Response.Write(dv(i).Row("id")) Else Response.Write("could not find the record") EndIf EndSub EndClass
123
Output:
124