Navigation

Search

Categories

On this page

Updating or Deleting a List of Records
Using Cookies With jQuery
Calling a Function in VB.NET
jQuery Collapsible Panel

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 240
This Year: 46
This Month: 3
This Week: 0
Comments: 0

Sign In
Pick a theme:

# Wednesday, March 31, 2010
Wednesday, March 31, 2010 3:51:30 PM (GMT Daylight Time, UTC+01:00) ( ASP.NET | SQL | VB.NET )


This is a nice example of how to pass a delimitted list of values to SQL Server and perform some kind of dbase function with those whether that be an UPDATE, DELETE or whatever.

First here is the sample stored procedure we are going to call updating each company sent to it by the PK value, id_company

USE [my_dbase]
GO
CREATE PROCEDURE [dbo].[p_UpdateCompany] 
    @id_assign int = NULL
AS
BEGIN

    SET NOCOUNT ON;

    UPDATE Companies 
    SET markedfordeletion = 1 --or whatever could be a delete statement as well    

END

Next, here is the VB.NET code used to call the sproc

Protected Sub btnCompanySubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim strConnection As SqlConnection
        Dim strSql As String
        Dim cmd As SqlCommand
        Dim CompanyValues As String = txtid_company.Text
        
        Dim CompanyList As New ArrayList
        CompanyList.AddRange(Split(CompanyValues, ","))
        
        strConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conString_Repository").ConnectionString)
        strSql = "p_UpdateCompany"
        cmd = New SqlCommand(strSql)
        cmd.CommandType = CommandType.StoredProcedure
        
        For i As Integer = 0 To CompanyList.Count - 1
            Dim CompanyVal As Integer = CompanyList(i)
            
            cmd.Parameters.Add("@id_Company", SqlDbType.Int, CompanyVal)
            Try
                strConnection.Open()
                cmd.Connection = strConnection
                cmd.ExecuteNonQuery()
            Finally
                strConnection.Close()
            End Try
        Next
    End Sub

<form id="form1" runat="server">
    <div>
        <table id="Companies">
            <tr>
                <td>Enter id_company values:<br />
                    (separated by commas)</td>
                <td><asp:TextBox ID="txtid_company" runat="server" TextMode="MultiLine" Rows="5" Columns="25" /></td>
            </tr>           
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnCompanySubmit" runat="server" onclick="btnCompanySubmit_Click" Text="Submit" />
                </td>
            </tr>           
        </table>
    </div>
    
    </form>
Comments [0] | | # 
# Friday, March 19, 2010
Friday, March 19, 2010 6:39:07 PM (GMT Standard Time, UTC+00:00) ( jQuery )


Probably the easiest way to use cookies with jQuery is to use Klaus Hartl’s cookie plugin:

http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/

Here’s an article with examples on how to use it

http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/

Comments [0] | | # 
# Wednesday, March 17, 2010
Wednesday, March 17, 2010 6:06:50 PM (GMT Standard Time, UTC+00:00) ( ASP.NET | VB.NET )


lblCompanyName.Text = GetCompanyName(intid_company).ToString()


Public Shared Function GetCompanyName(ByVal id_company As Integer) As String
        Dim result As String = String.Empty
        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnString").ConnectionString)

        Dim cmd As New SqlCommand("getCompanyName", con)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@id_company", id_company)
        Using con
            con.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            If reader.Read() Then
                result = CType(reader("CompanyName"), String)
            End If
        End Using
        Return result
End Function
Comments [0] | | # 
# Wednesday, March 10, 2010
Wednesday, March 10, 2010 9:21:03 PM (GMT Standard Time, UTC+00:00) ( jQuery )


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" />
<title>Untitled Document</title>
<style> 
/*CollapsiblePanel*/ 
.ContainerPanel 
{ 
       width:400px; 
       border:1px; 
       border-color:#1052a0;      
       border-style:double double double double; 
} 
.collapsePanelHeader 
{ 
       width:400px; 
       height:25px; 
       background-image: url(http://www.asp.net/AJAX/AjaxControlToolkit/Samples/images/bg-menu-main.png); 
       background-repeat:repeat-x; 
       color:#FFF; 
       font-weight:bold; 
} 
.HeaderContent 
{ 
       float:left; 
       padding-left:5px;
       font-family:Arial, Helvetica, sans-serif;
       font-size: small;
} 
.Content 
{ 
       
} 
.ArrowExpand 
{ 
       background-image: url(http://www.asp.net/AJAX/AjaxControlToolkit/Samples/images/expand_blue.jpg);
       width:13px; 
       height:13px; 
       float:right; 
       margin-top:7px; 
       margin-right:5px;
       margin-bottom: 5px; 
} 
.ArrowExpand:hover 
{ 
       cursor:hand; 
} 
.ArrowClose 
{ 
       background-image: url(http://www.asp.net/AJAX/AjaxControlToolkit/Samples/images/collapse_blue.jpg); 
       width:13px; 
       height:13px; 
       float:right; 
       margin-top:7px; 
       margin-right:5px;
       margin-bottom: 5px;
} 
.ArrowClose:hover 
{ 
       cursor:hand; 
} 
</style>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script> 
       <script language="javascript"> 
            $(document).ready(function() {
                $("DIV.ContainerPanel > DIV.collapsePanelHeader ").toggle( 
                function() {
                $(this).html( $(this).html().replace("(Show","(Hide") )
                    $(this).next("div.Content").show("slow");
                    $("DIV.ArrowExpand",this).attr("class", "ArrowClose");
                },
                function() {                   
                $(this).html( $(this).html().replace("(Hide","(Show") )
                    $(this).next("div.Content").hide("slow");
                    $("DIV.ArrowClose",this).attr("class", "ArrowExpand");
                });             
            });           
        </script>
</head> 
<body>
<div id="ContainerPanel" class="ContainerPanel">
    <div id="header" class="collapsePanelHeader"> 
        <div id="dvHeaderText" class="HeaderContent">jQuery Collapsible Panel1 (Show Details...)</div> 
        <div id="dvArrow" class="ArrowExpand"></div> 
    </div> 
    <div id="dvContent" class="Content" style="display:none"> 
        /*Content*/ 
    </div> 
</div> 
   
</body>
</html>
Comments [0] | | #