Wednesday, August 10, 2011

Nested Repeater in asp.net

No comments:


--Tables used.


CREATE TABLE [dbo].[user_types](
[ut_id] [int] IDENTITY(1,1) NOT NULL,
[ut_name] [varchar](50) NULL
)
------------------------
CREATE TABLE [dbo].[users](
[u_id] [int] IDENTITY(1,1) NOT NULL,
[u_ut_id] [int] NULL,
[u_name] [varchar](50) NULL,
[u_password] [varchar](50) NULL
)
-------------------------

Default.aspx

<body>
    <form id="form1" runat="server">
    <div>
    <%@ Import Namespace="System.Data" %>
        <h1 style="background-color:Lime;">Nested Repeater</h1>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <h2 style="background-color:Aqua;" >Children of <%# DataBinder.Eval(Container.DataItem, "ut_name")%></h2>
                <asp:Repeater ID="Repeater2" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("typerelation") %>' runat="server">
                    <ItemTemplate>
                        <h3 style="background-color:Olive;">child item <%# DataBinder.Eval(Container.DataItem, "[\"u_name\"]")%></h3>
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>

-----------------------------

Default.aspx.cs

using System.Data;
using System.Data.SqlClient;


protected void Page_Load(object sender, EventArgs e)
    {
        DataSet DsRep = new DataSet();
        SqlCommand SqlCmd = new SqlCommand();
        DataTable DtRep;
        string con = @"Server=.\SQLEXPRESS; Database=tutorials; uid=sa; pwd=asdf123*;";
        string command = "";


        command = "select ut_id,ut_name from user_types";
        DtRep = new DataTable();
        new SqlDataAdapter(command, con).Fill(DsRep, "parent");
     
        command = "select u_id,u_ut_id,u_name from users";
        DtRep=new DataTable();
        new SqlDataAdapter(command, con).Fill(DsRep, "child");


        DsRep.Relations.Add("typerelation", DsRep.Tables["parent"].Columns["ut_id"], DsRep.Tables["child"].Columns["u_ut_id"]);


        Repeater1.DataSource = DsRep.Tables[0];
        Page.DataBind();
    }

Thursday, July 28, 2011

PHP and MS SQL Server connection in IIS 7

No comments:

<?php
$connectionInfo = array("UID" => "sa", "PWD" => "asdf123*", "Database"=>"testdb");
$serverName = ".\SQLEXPRESS";
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )
{
     echo "Connection established...<br />";
}
else
{
     echo "Connection could not be established.\n";
     die( print_r( sqlsrv_errors(), true));
}

//Lets do some sample sql select.

// Send a select query to MSSQL
$stmt = sqlsrv_query($conn,'SELECT * FROM users');
if( $stmt === false)
{
     echo "Error in query preparation/execution.\n";
     die( print_r( sqlsrv_errors(), true));
}
// Check if there were any records
if (sqlsrv_has_rows($stmt)==false) {
    echo 'No records found';
} else {
?>
<table width="100%" border="2px">
<?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { ?>
<tr>
    <td><?php echo $row['name']; ?></td>
    <td><?php echo $row['designation']; ?></td>
</tr>
<?php } ?>
</table>
<br /> <?php
}
// Free the query result
sqlsrv_free_stmt($stmt);

/* Close the connection. */
sqlsrv_close($conn);

phpinfo();
?>

Sunday, July 17, 2011

windows in Ubuntu 11 as Virtual OS

No comments:

Running windows in Ubuntu 11 as Virtual OS.
Running Visual Studio 2010 Express and SQL Server Express Edition 2008 R2 in virtual OS
Google Chrome, FileZilla, and Virtual Box in Ubuntu.