Private: MY Note


Creating paging user control + store procedure

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

<%@ Control Language=C# AutoEventWireup=true CodeFile=paging1.ascx.cs Inherits=Controls_Paging_paging1 %>
<div class=”PagingStyle”>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ width=”100%”>
<tr>
<td align=”left”>
<asp:Label ID=”lblPageOf” CssClass=”PageOf” meta:resourceKey=”lblPageOf” runat=”Server”>หน้าที่ {0} ของ {1}</asp:Label>
</td>
<td align=”right”>
<asp:LinkButton ID=”lnkFirst” CssClass=”FirstPage” Text=”lnkFirst หน้าแรก” runat=”Server” meta:resourceKey=”lnkFirst” OnClick=”lnkFirst_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:LinkButton ID=”lnkPrevious” CssClass=”PreviousPage” Text=”lnkPrevious หน้าที่แล้ว” runat=”Server” meta:resourceKey=”lnkPrevious” OnClick=”lnkPrevious_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:Repeater ID=”rptPageNumbers” runat=”server” OnItemCommand=”rptPageNumbers_ItemCommand” OnItemDataBound=”rptPageNumbers_ItemDataBound”>
<ItemTemplate>
<asp:LinkButton ID=”lnkPageNumber” CssClass=”PageNumber” CommandName=”Selected” runat=”Server” CausesValidation=”False”></asp:LinkButton>
</ItemTemplate>
</asp:Repeater> 
<asp:LinkButton ID=”lnkNext” CssClass=”NextPage” Text=”lnkNext” runat=”Server” meta:resourceKey=”lnkNext” OnClick=”lnkNext_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:LinkButton ID=”lnkLast” CssClass=”LastPage” Text=”lnkLast” runat=”Server” meta:resourceKey=”lnkLast” OnClick=”lnkLast_Click” CausesValidation=”False”></asp:LinkButton> 
</td>
</tr>
</table>
</div>


(more…)

ความรู้เกี่ยวกับการทำ Object Serialization และ Deserialization

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

http://www.thaiwebdev.com/forums/index.php?showtopic=31&mode=threaded

How to call SQL Server stored procedures in ASP.NET

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

private void Button1_Click(object sender, System.EventArgs e)
{

            //Create a connection to the SQL Server; modify the connection string for your environment.

            SqlConnection MyConnection = new SqlConnection(”server=(local);database=pubs;UID=sa;PWD=;”);

            //Create a DataAdapter, and then provide the name of the stored procedure.

            SqlDataAdapter MyDataAdapter = new SqlDataAdapter(”GetAuthorsByLastName”, MyConnection);

            //Set the command type as StoredProcedure.

            MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            //Create and add a parameter to Parameters collection for the stored procedure.

            MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(”@au_lname”, SqlDbType.VarChar, 40));

            //Assign the search value to the parameter.

            MyDataAdapter.SelectCommand.Parameters["@au_lname"].Value = (TextBox1.Text).Trim();

            //Create and add an output parameter to the Parameters collection.

            MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(”@RowCount”, SqlDbType.Int, 4));

            //Set the direction for the parameter. This parameter returns the Rows that are returned.

            MyDataAdapter.SelectCommand.Parameters["@RowCount"].Direction = ParameterDirection.Output;

            //Create a new DataSet to hold the records.

            DataSet DS = new DataSet();

           

            //Fill the DataSet with the rows that are returned.

            MyDataAdapter.Fill(DS, “AuthorsByLastName”);

            //Get the number of rows returned, and assign it to the Label control.

            //Label2.Text = DS.Tables(0).Rows.Count().ToString() & ” Rows Found!”

            Label2.Text = MyDataAdapter.SelectCommand.Parameters[1].Value + ” Rows Found!”;

            //Set the data source for the DataGrid as the DataSet that holds the rows.

            DataGrid1.DataSource = DS.Tables["AuthorsByLastName"].DefaultView;

            //NOTE: If you do not call this method, the DataGrid is not displayed!

            DataGrid1 .DataBind();

            MyDataAdapter.Dispose(); //Dispose the DataAdapter.

            MyConnection.Close(); //Close the connection.

}