Friday, February 12, 2010

How to retrive data from database by C#

//First we should add the following Namespace

using System.Data;
using System.Data.OleDb;


{
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\ERDATA.mdb;Persist Security Info=True");
        connection.Open();
        String query = "Select sum(amount) FROM Tran";
        OleDbDataAdapter dadaptor = new OleDbDataAdapter(query, connection);
        DataSet ds = new DataSet();
        dadaptor.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
            String sum = ds.Tables[0].Rows[0][0].ToString();
            lblTotal.Text = "Rs. " + sum;
        }
        connection.Close();
        connection.Dispose();
}

Tuesday, February 9, 2010

C# code for Insert Data into Database

//First we should add the following Namespace

using System.Data;
using System.Data.OleDb;

//Database connection code

{
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\SamDB.mdb;Persist Security Info=True");
connection.Open();
String query;
query = "insert into sample(NAME,ADDRESS,PHONENO)" +
             "VALUES ('" + custName + "'," + txtAddress.Text.Trim() + ",'" + txtMobileNumber.Text.Trim() + "')";
       
OleDbCommand command = new OleDbCommand(query, connection);
int status = command.ExecuteNonQuery();
if (status > 0)
lblTranStatus.Text = status + " Data inserted Successfully";
else
      lblTranStatus.Text = "FAILED!!!";

connection.Close();
connection.Dispose();
}

Monday, February 8, 2010

PHP code for Database connection

//Database connection code


//mysql_connect(servername,username,password);

$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "
";
}
mysql_close($con);
?>

Thursday, February 4, 2010

What is a database?

A database is a collection of information that is organized so that it can easily be accessed, managed, and updated. A database is an integrated collection of logically-related records or files consolidated into a common pool that provides data for one or more multiple uses. One way of classifying databases involves the type of content, for example: bibliographic, full-text, numeric, image. Other classification methods start from examining database models or database architectures: see below. Software organizes the data in a database according to a database model. As of 2010[update] the relational model occurs most commonly. Other models such as the hierarchical model and the network model use a more explicit representation of relationships.