Programalama > ASP.NET

Etiketler: database, search

Ort. 0
Puan ver:
<%@ Page Language="VB" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="VB" runat="server">

	Sub btnSearch_OnClick(sender as Object, e as EventArgs)
		Dim objConnection As SqlConnection
		Dim objCommand    As SqlCommand
		Dim objAdapter    As SqlDataAdapter
		Dim objDataSet    As DataSet
		Dim strSearch     As String
        Dim strSQLQuery As String
        'search stringini al
        strSearch = txtSearch.Text
        'kontrol
		If Len(Trim(strSearch)) > 0 Then
            ' bağlantı
            objConnection = New SqlConnection("Data Source=serveradı;" _
            & "Initial Catalog=databaseadı;User Id=kullanıcı;Password=şifre;" _
            & "Connect Timeout=15;Network Library=dbmssocn;")

			' SQL query 
            strSQLQuery = "SELECT * FROM table " _
            & "WHERE fieldLIKE '%" & Replace(strSearch, "'", "''") & "%' " _
            & "ORDER BY field;"
objCommand = New SqlCommand(strSQLQuery, objConnection)
objAdapter = New SqlDataAdapter(objCommand)
objDataSet = New DataSet()
objAdapter.Fill(objDataSet)
dgPaging.DataSource = objDataSet
            dgPaging.DataBind()

			objConnection.Close()
		Else
            txtSearch.Text = "Arama Kelimelerini Giriniz"
		End If
	End Sub

</script>
<html>
<head>
  <title>ASP.NET Database Search</title>
</head>
<body>

<form id="Form1" runat="server">

<p>

<asp:textbox id="txtSearch" runat="server" />

<asp:button id="btnSearch" runat="server"
	text    = "Search"
	onclick = "btnSearch_OnClick"
/>

</p>

<p> </p>

<asp:datagrid id="dgPaging" runat="server"
	headerstyle-font-bold="True" gridlines="None">
<HeaderStyle Font-Bold="True"></HeaderStyle>
</asp:datagrid>

</form>

<hr />

</body>
</html>


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.