Showing posts with label mssql. Show all posts
Showing posts with label mssql. Show all posts

Wednesday, March 4, 2015

SQL Server 2014 Express LocalDB

No comments:

Microsoft SQL Server 2014 Express LocalDB is an execution mode of SQL Server Express targeted to program developers. LocalDB installation copies a minimal set of files necessary to start the SQL Server Database Engine. Once LocalDB is installed, developers initiate a connection by using a special connection string. When connecting, the necessary SQL Server infrastructure is automatically created and started, enabling the application to use the database without complex or time consuming configuration tasks. Developer Tools can provide developers with a SQL Server Database Engine that lets them write and test Transact-SQL code without having to manage a full server instance of SQL Server. An instance of SQL Server Express LocalDB is managed by using the SqlLocalDB.exe utility. SQL Server Express LocalDB should be used in place of the SQL Server Express user instance feature which is deprecated.

https://msdn.microsoft.com/en-us/library/hh510202.aspx

Friday, February 28, 2014

Sample MS SQL trigger code

No comments:
CREATE TRIGGER trg_users
ON  dbo.users
FOR  INSERT,UPDATE
AS
BEGIN
    RAISERROR('This is a test', 16, 1)
END
GO

Friday, November 30, 2012

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();
?>