web 2.0

ASP.NET(vb.net) & Microsoft Access Search Rows Record

ASP.NET(vb.net) & Microsoft Access Search Rows Record - This is  example scripts how to use ASP.NET search the rows record in database Microsoft access (.mdb) database.

ShotDev Focus:
- ASP.NET(vb.net) & Microsoft Access Search Rows Record

Example

AspNetAccessSearchRecord.aspx

  1. <%@ import Namespace="System.Data" %>  
  2. <%@ import Namespace="System.Data.OleDb" %>  
  3. <%@ Page Language="VB" %>  
  4. <script runat="server">  
  5. Dim strKeyWord As String  
  6. Sub Page_Load(sender As Object, e As EventArgs)  
  7. strKeyWord = Me.txtKeyWord.Text  
  8. End Sub  
  9.   
  10. Sub BindData()  
  11.   
  12. Dim objConn As New OleDbConnection  
  13. Dim objCmd As New OleDbCommand  
  14. Dim dtAdapter As New OleDbDataAdapter  
  15. Dim ds As New DataSet  
  16. Dim strConnString,strSQL As String  
  17.   
  18. strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"  
  19. strSQL = "SELECT * FROM customer WHERE (Name like '%"& strKeyWord &"%' OR Email like '%"& strKeyWord &"%') "  
  20.   
  21. objConn.ConnectionString = strConnString  
  22. With objCmd  
  23. .Connection = objConn  
  24. .CommandText = strSQL  
  25. .CommandType = CommandType.Text  
  26. End With  
  27. dtAdapter.SelectCommand = objCmd  
  28.   
  29. dtAdapter.Fill(ds)  
  30.   
  31. '*** BindData to GridView ***'  
  32. myGridView.DataSource = ds  
  33. myGridView.DataBind()  
  34.   
  35. dtAdapter = Nothing  
  36. objConn.Close()  
  37. objConn = Nothing  
  38.   
  39. End Sub  
  40.   
  41. Sub myGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)  
  42. '*** CustomerID ***'  
  43. Dim lblCustomerID As Label = CType(e.Row.FindControl("lblCustomerID"),Label)  
  44. IF Not IsNothing(lblCustomerID) Then  
  45. lblCustomerID.Text = e.Row.DataItem("CustomerID")  
  46. End IF  
  47.   
  48. '*** Name ***'  
  49. Dim lblName As Label = CType(e.Row.FindControl("lblName"),Label)  
  50. IF Not IsNothing(lblName) Then  
  51. lblName.Text = e.Row.DataItem("Name")  
  52. End IF  
  53.   
  54. '*** Email ***'  
  55. Dim lblEmail As Label = CType(e.Row.FindControl("lblEmail"),Label)  
  56. IF Not IsNothing(lblEmail) Then  
  57. lblEmail.Text = e.Row.DataItem("Email")  
  58. End IF  
  59.   
  60. '*** CountryCode ***'  
  61. Dim lblCountryCode As Label = CType(e.Row.FindControl("lblCountryCode"),Label)  
  62. IF Not IsNothing(lblCountryCode) Then  
  63. lblCountryCode.Text = e.Row.DataItem("CountryCode")  
  64. End IF  
  65.   
  66. '*** Budget ***'  
  67. Dim lblBudget As Label = CType(e.Row.FindControl("lblBudget"),Label)  
  68. IF Not IsNothing(lblBudget) Then  
  69. lblBudget.Text = FormatNumber(e.Row.DataItem("Budget"),2)  
  70. End IF  
  71.   
  72. '*** Used ***'  
  73. Dim lblUsed As Label = CType(e.Row.FindControl("lblUsed"),Label)  
  74. IF Not IsNothing(lblUsed) Then  
  75. lblUsed.Text = FormatNumber(e.Row.DataItem("Used"),2)  
  76. End IF  
  77. End Sub  
  78.   
  79. Sub btnSearch_Click(sender As Object, e As EventArgs)  
  80. BindData()  
  81. End Sub  
  82.   
  83. </script>  
  84. <html>  
  85. <head>  
  86. <title>ShotDev.Com Tutorial</title>  
  87. </head>  
  88. <body>  
  89. <form id="form1" runat="server">  
  90. <asp:Label id="lblKeyword" runat="server" text="Keyword"></asp:Label>  
  91. <asp:TextBox id="txtKeyWord" runat="server"></asp:TextBox>  
  92. <asp:Button id="btnSearch" onclick="btnSearch_Click" runat="server" Text="Search"></asp:Button>  
  93. <br />  
  94. <br />  
  95. <asp:GridView id="myGridView" runat="server"  
  96. AutoGenerateColumns="False" onRowDataBound="myGridView_RowDataBound">  
  97. <HeaderStyle backcolor="#cccccc"></HeaderStyle>  
  98. <AlternatingRowStyle backcolor="#e8e8e8"></AlternatingRowStyle>  
  99. <Columns>  
  100. <asp:TemplateField HeaderText="CustomerID">  
  101. <ItemTemplate>  
  102. <asp:Label id="lblCustomerID" runat="server"></asp:Label>  
  103. </ItemTemplate>  
  104. </asp:TemplateField>  
  105. <asp:TemplateField HeaderText="Name">  
  106. <ItemTemplate>  
  107. <asp:Label id="lblName" runat="server"></asp:Label>  
  108. </ItemTemplate>  
  109. </asp:TemplateField>  
  110. <asp:TemplateField HeaderText="Email">  
  111. <ItemTemplate>  
  112. <asp:Label id="lblEmail" runat="server"></asp:Label>  
  113. </ItemTemplate>  
  114. </asp:TemplateField>  
  115. <asp:TemplateField HeaderText="CountryCode">  
  116. <ItemTemplate>  
  117. <asp:Label id="lblCountryCode" runat="server"></asp:Label>  
  118. </ItemTemplate>  
  119. </asp:TemplateField>  
  120. <asp:TemplateField HeaderText="Budget">  
  121. <ItemTemplate>  
  122. <asp:Label id="lblBudget" runat="server"></asp:Label>  
  123. </ItemTemplate>  
  124. </asp:TemplateField>  
  125. <asp:TemplateField HeaderText="Used">  
  126. <ItemTemplate>  
  127. <asp:Label id="lblUsed" runat="server"></asp:Label>  
  128. </ItemTemplate>  
  129. </asp:TemplateField>  
  130. </Columns>  
  131. </asp:GridView>  
  132. </form>  
  133. </body>  
  134. </html>  

Screenshot

ASP.NET(vb.net) & Microsoft Access Search Rows Record
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.