Connectionstring in web.config file and call from asp.net

Quote

we add connection string in web.config file.

<connectionStrings>
<add name=”LocalSqlServer” connectionString=”data source=.\SQLEXPRESS; Initial Catelog=”example” Integrated Security=true” providerName=”System.Data.SqlClient”   />
</connectionStrings>

From web.config file call the connectionstring

uisng system.configuration;

using system.Data.SqlClient;

string connectionString=ConfigurationManager.ConnetionStrings[“Name of Connection”].ConnectionSrting;

sqlConnection con=new SqlConnection(ConnectionString);

Advertisements

AutoComplete using Handler

<asp:textbox id=”txtAutoComplete” runat=”server”/>

add This to Script

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
       <script src=http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js; type="text/javascript"></script>
     <script type="text/javascript">
      $(document).ready(function () {
        $("#<%=txtAutoComplete.ClientID %>").autocomplete('select.ashx');
      });

 

Imports System.Web
Imports System.Web.Services

Public Class _select
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        If Not [String].IsNullOrEmpty(context.Request.QueryString("q")) Then
            For Each s As String In GetAutoCompleteValues(context.Request.QueryString("q"))
                context.Response.Write(s + Environment.NewLine)
            Next
        End If

    End Sub
    Private Function GetAutoCompleteValues(ByVal prefixText As String)
        Dim db As New DataClasses1DataContext()
        Dim data = db.tblKitTemplateHeaders.Where(Function(n) n.CustomKitPartNumber.StartsWith(prefixText)).OrderBy _
            (Function(xe) xe.CustomKitPartNumber).Select(Function(c) c.CustomKitPartNumber).ToList()
        Return data
    End Function

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 End Class

Ajax

First Register ajaxcontrol toolkit
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
 <asp:TextBox ID="txtAutoComplete" runat="server"></asp:TextBox>
        <ajax:AutoCompleteExtender ID="atcExteder" runat="server" TargetControlID="txtAutoComplete"
            ServiceMethod="GetKits" ServicePath="~/AutoComplete.asmx" MinimumPrefixLength="1"
            UseContextKey="true" CompletionInterval="500">
        </ajax:AutoCompleteExtender>

 add this method to autocomplete.aspx.cs

  <System.Web.Services.WebMethod()> _
    Public Function GetKits(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
        Dim db As New DataClasses1DataContext()
        Dim data = db.tblKitTemplateHeaders.Where(Function(n) n.CustomKitPartNumber.StartsWith(prefixText)).OrderBy _
            (Function(xe) xe.CustomKitPartNumber).Select(Function(c) c.CustomKitPartNumber).Take(count).ToList()
        Return data
    End Function

Hello world!

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can always preview any post or edit it before you share it to the world.