Wednesday, August 27, 2014

ASP.NET with C# Disconnected architecture

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

public partial class Default2 : System.Web.UI.Page
{
    string str = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Sagar\Documents\Visual Studio 2010\WebSites\kalp\App_Data\example.mdf;Integrated Security=True;User Instance=True";
    SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(str);
        dispdata();  
    }
    protected void submit_Click(object sender, EventArgs e)
    {

        con.Open();
        SqlCommand cmd = new SqlCommand("insert into tblstu values('"+name.Text+"','"+city.Text+"')",con);
        cmd.ExecuteNonQuery();
        Response.Write("<script>alert('record inserted successfully');</script>");
        con.Close();
    }
    protected void dispdata()
    {
        DataTable dt = new DataTable();
        SqlCommand cmd = new SqlCommand("select * from tblstu",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        GridView1.DataSource=dt;
        GridView1.DataBind();

    }
}

Wednesday, August 6, 2014

PAGING BY NUMBERS LENGTH

<?php
include("./connections/connect.php");
$sql="SELECT count(student.grno) from student";
$res=mysql_query($sql);

while($row=mysql_fetch_array($res,MYSQL_NUM))
{

$pages=$row[0]/5;
}
echo "No of pages....:",$pages;
echo "<table><TR>";
for($x=0;$x<=($pages*5);$x=$x+5)
{
echo "<TD><a href='paging.php?nor=".$x."'>",$x,"-",$x+5,"</a> | </td>";
}
echo "</table></TR>";

$sql = "SELECT STUDENT.GRNO,STUDENT.NAME,CITY.CNAME FROM STUDENT,CITY WHERE STUDENT.CITY=CITY.CID ORDER BY student.GRNO ASC LIMIT ".($_REQUEST["nor"]+1).", 5 ";
$res=mysql_query($sql);
echo "<table>";
while($row=mysql_fetch_row($res))
{
echo "<TR>";
foreach($row as $k=>$v)
{
echo "<TD>",$v,"</td>";
}
echo "</tr>";

}
echo "</table>";
?>


Tuesday, August 5, 2014

PAGING USING LETTERS

<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass ='';

echo "<table><TR>";
for($x=65;$x<91;$x++)
{
echo "<td><a href='pagingbyletter.php?letter=",chr($x),"'>".chr($x)."</a></td>";
}
echo "</tr></table>";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbpractice');
/* Get total number of records */
if(!isset($_REQUEST['letter']))
{
$_REQUEST['letter']='a';
}

$sql = "SELECT eid, ename,phone ".
"FROM tblemp where ename like '".$_REQUEST['letter']."%'";
echo $sql,"<BR>";
$retval = mysql_query( $sql, $conn );

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "EMP ID :{$row['eid']} <br> ".
"EMP NAME : {$row['ename']} <br> ".
"EMP SALARY : {$row['phone']} <br> ".
"--------------------------------<br>";
}
mysql_close($conn);
?>

PAGING IN PHP

<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass ='';
$rec_limit = 5;

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbpractice');
/* Get total number of records */
$sql = "SELECT count(eid) FROM tblemp ";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
//record counter
$rec_count = $row[0];

if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);

$sql = "SELECT eid, ename,phone ".
"FROM tblemp ".
"LIMIT $offset, $rec_limit";

$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "EMP ID :{$row['eid']} <br> ".
"EMP NAME : {$row['ename']} <br> ".
"EMP SALARY : {$row['phone']} <br> ".
"--------------------------------<br>";
}

if( $page > 0 )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a> |";
echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>";
}
else if( $page == 0 )
{
echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a>";
}
mysql_close($conn);
?>

Saturday, August 2, 2014

swaping programme

#include 
 
int main()
{
   int x, y, temp;
 
   printf("Enter the value of x and y\n");
   scanf("%d%d", &x, &y);
 
   printf("Before Swapping\nx = %d\ny = %d\n",x,y);
 
   temp = x;
   x    = y;
   y    = temp;
 
   printf("After Swapping\nx = %d\ny = %d\n",x,y);
 
   return 0;
}

 
#include 
 
int main()
{
   int a, b;
 
   printf("Enter two integers to swap\n");
   scanf("%d%d", &a, &b);
 
   a = a + b;
   b = a - b;
   a = a - b;
 
   printf("a = %d\nb = %d\n",a,b);
   return 0;
}

Android tutorial