Programming in almost language

Thi s is the site where you may share your knowledge and experience to eachother..

Archive for May, 2008

Oracle is best!! no SQL Server is best!! lets discuss !!

Posted by Praveen Kumar on May 13, 2008

Here its a hot discussion is going to start, some people say Oracle is best! and some says SQL Server is best!!

Lets see what we get conclusion

Platform comparison

SQL Server 2000 only works on Windows-based platforms, including Windows 9x, Windows NT, Windows 2000 and Windows CE.

In comparison with SQL Server 2000, Oracle 9i Database supports all known platforms, including Windows-based platforms, AIX-Based Systems, Compaq Tru64 UNIX, HP 9000 Series HP-UX, Linux Intel, Sun Solaris and so on.

Hardware requirements

To install SQL Server 2000, you should have the Intel or compatible platforms and the following hardware:

Hardware Requirements

Processor

Pentium 166 MHz or higher

Memory

32 MB RAM (minimum for Desktop Engine),
64 MB RAM (minimum for all other editions),
128 MB RAM or more recommended

Hard disk space

270 MB (full installation),
250 MB (typical),
95 MB (minimum),
Desktop Engine: 44 MB
Analysis Services: 50 MB minimum and 130 MB typical
English Query: 80 MB

To install Oracle 9i under the Intel or compatible platforms, you should have the following hardware:

Hardware Requirements

Processor

Pentium 166 MHz or higher

Memory

RAM: 128 MB (256 MB recommended)
Virtual Memory: Initial Size 200 MB, Maximum Size 400 MB

Hard disk space

140 MB on the System Drive
plus 4.5 GB for the Oracle Home Drive (FAT)
or 2.8 GB for the Oracle Home Drive (NTFS)

To install Oracle 9i Database under the UNIX Systems, such as AIX-Based Systems, Compaq Tru64 UNIX, HP 9000 Series HP-UX, and Sun Solaris, you should have the following hardware:

Hardware Requirements

Memory

A minimum of 512 MB RAM

Hard disk space

4.5 GB

Swap Space

A minimum of 2 x RAM or 400 MB, whichever is greater

Performance comparison

It is not easy to make the performance comparison between SQL Server 2000 and Oracle 9i Database. The performance of your databases depends rather from the experience of the database developers and database administrator than from the database’s provider. You can use both of these RDBMS to build stable and efficient system. However, it is possible to define the typical transactions, which used in inventory control systems, airline reservation systems and banking systems. After defining these typical transactions, it is possible to run them under the different database management systems working on the different hardware and software platforms.

Both SQL Server 2000 and Oracle 9i Database support the ANSI SQL-92 entry level and do not support the ANSI SQL-92 intermediate level.

T-SQL vs PL/SQL

The dialect of SQL supported by Microsoft SQL Server 2000 is called Transact-SQL (T-SQL).

The dialect of SQL supported by Oracle 9i Database is called PL/SQL.

PL/SQL is the most powerful language than T-SQL

Feature

PL/SQL

T-SQL

Indexes

B-Tree indexes,
Bitmap indexes,
Partitioned indexes,
Function-based indexes,
Domain indexes

B-Tree indexes

Tables

Relational tables,
Object tables,
Temporary tables,
Partitioned tables,
External tables,
Index organized tables

Relational tables,
Temporary tables

Triggers

BEFORE triggers,
AFTER triggers,
INSTEAD OF triggers,
Database Event triggers

AFTER triggers,
INSTEAD OF triggers

Procedures

PL/SQL statements,
Java methods,
third-generation language
(3GL) routines

T-SQL statements

Arrays

Supported

Not Supported

SQL Server 2000 and Oracle 9i limits

Feature

SQL Server 2000

Oracle 9i Database

database name length

128

8

column name length

128

30

index name length

128

30

table name length

128

30

view name length

128

30

stored procedure name length

128

30

max columns per index

16

32

max char() size

8000

2000

max varchar() size

8000

4000

max columns per table

1024

1000

max table row length

8036

25500

max query size

16777216

16777216

recursive subqueries

40

64

constant string size in SELECT

16777207

4000

constant string size in WHERE

8000

4000

Conclusion

It is not true that SQL Server 2000 is better than Oracle 9i or vice versa. Both products can be used to build stable and efficient system and the stability and effectiveness of your applications and databases depend rather from the experience of the database developers and database administrator than from the database’s provider. But SQL Server 2000 has some advantages in comparison with Oracle 9i and vice versa.


The SQL Server 2000 advantages:

  • SQL Server 2000 is cheaper to buy than Oracle 9i Database.

  • SQL Server 2000 holds the top TPC-C performance and price/performance results.

  • SQL Server 2000 is generally accepted as easier to install, use and manage.

The Oracle 9i Database advantages:

  • Oracle 9i Database supports all known platforms, not only the Windows-based platforms.

  • PL/SQL is more powerful language than T-SQL.

  • More fine-tuning to the configuration can be done via start-up parameters.

Posted in Discussion | 4 Comments »

Dynamic GridView(Edit,Delete,Insert,Select) Just copy paste and enjoy it

Posted by Praveen Kumar on May 9, 2008

Design(View Part)

<%@ Page Language=”C#” Title=”Untitled Page” CodeFile=”~/createaccount.aspx.cs” Inherits=”createaccount” %>
<script type=”text/javascript”>
function comparetext()
{    if((document.getElementById(txt_newpwd).contains)==(document.getElementById(txt_cnfpwd).contains))
alert(“hi”);
else
alert(“sorry”);
}</script>
<div id=”container”>
<div class=”header”>
<div class=”logo”>
<h1>Create Account</h1>
</div>
</div>
</div>
<div>

<asp:Panel ID=”p_Panel1″ runat=”server” Height=”590px” Style=”left: 0px; position: relative;
top: 0px;” Width=”674px” BorderColor=”Silver” BorderStyle=”Solid” BorderWidth=”1px”>
<div Style=”left: 0px; position: absolute; top: 0px; width: 336px; height: 582px;”>

<asp:GridView ID=”GridView_account” runat=”server” AutoGenerateColumns=”false” ShowFooter=”True”
OnRowCancelingEdit=”GridView_account_RowCancelingEdit” OnRowEditing=”GridView_account_RowEditing”
OnRowUpdating=”GridView_account_RowUpdating” OnRowCommand=”GridView_account_RowCommand”
OnRowDeleting=”GridView_account_RowDeleting” OnSelectedIndexChanged=”GridView_account_SelectedIndexChanged” DataKeyNames=”CID” Height=”110px” Width=”497px” >
<Columns>
<asp:TemplateField HeaderText=”ID” SortExpression=”departmentid”>
<ItemTemplate>
<asp:Label ID=”label_accid” runat=”server” Text=’<%# Bind(“CID”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”User Name (required)” SortExpression=”CID”>
<EditItemTemplate>
<asp:TextBox ID=”txt_name” runat=”server” Text=’<%# Bind(“NAME”) %>’></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txt_newname” runat=”server” ></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID=”label_name” runat=”server” Text=’<%# Bind(“NAME”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Password (required)”>
<EditItemTemplate>
<asp:TextBox ID=”txt_password” runat=”server” Text=’<%# Bind(“PASSWORD”) %>’ TextMode=”Password”></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txt_newpassword” runat=”server” ></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID=”label_pwd” runat=”server” Text=”*****”></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Email Address (required)” SortExpression=”CID”>
<EditItemTemplate>
<asp:TextBox ID=”txt_email” runat=”server” Text=’<%# Bind(“EMAIL”) %>’></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txt_newemail” runat=”server” ></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID=”label_email” runat=”server” Text=’<%# Bind(“EMAIL”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Options” ShowHeader=”False”>
<EditItemTemplate>
<asp:LinkButton ID=”LinkButton_update” runat=”server” CausesValidation=”True” CommandName=”Update” Text=”Update”></asp:LinkButton>
<asp:LinkButton ID=”LinkButton_cancel” runat=”server” CausesValidation=”False” CommandName=”Cancel” Text=”Cancel”></asp:LinkButton>
<asp:LinkButton ID=”LinkButton_delete” runat=”server” CausesValidation=”False” CommandName=”Delete” Text=”Delete”></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID=”LinkButton_addnew” runat=”server” CausesValidation=”False” CommandName=”AddNew” Text=”Add New”></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID=”LinkButton_edit” runat=”server” CausesValidation=”False” CommandName=”Edit” Text=”Edit”></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Manage Role” ShowHeader=”False”>
<ItemTemplate>
<asp:LinkButton ID=”Selectbtn” runat=”server” CausesValidation=”False” CommandName=”Select” Text=”Select”></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Button” />
<div Style=”left: 263px; position: absolute; top: -30px; width: 185px; height: 20px;” >
<asp:RadioButton ID=”adminradio” runat=”server” GroupName=”usertype” Text=”Admin”/>
<asp:RadioButton ID=”empradio” runat=”server” GroupName=”usertype” Text=”Employee” />
<asp:RadioButton ID=”genradio” runat=”server” GroupName=”usertype” Text=”General” Width=”54px” Checked=”True” />
</div>
</div>
</asp:Panel>
</div>

Code Behind

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using System.Security.Cryptography;
using System.Text;

public partial class createaccount : System.Web.UI.Page
{
OdbcConnection con;
OdbcCommand cmd;
OdbcDataReader myreader;
ConnectionClass objCon;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillgridview();
}
}//

private void fillgridview()
{
objCon = new ConnectionClass();
con = new OdbcConnection();
con = objCon.Connect_thru_config();
con.Open();
string str = “select *from FK_viwUser”;
//string strrole = “select name from FK_TBLROLE”;
OdbcCommand cmd = new OdbcCommand(str, con);
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView_account.DataSource = ds;
GridView_account.DataBind();
con.Close();
}//end of fillgridview

public enum ValidationCode
{
LoginFailed = 1,
LoginSucceeded = 2,
ConnectionFailed = 3,
UnspecifiedFailure = 4,
LoginCreated = 5
}//end of ValidationCode

protected void GridView_account_SelectedIndexChanged(object sender, EventArgs e)
{
string selectedID = ((Label)GridView_account.SelectedRow.FindControl(“label_accid”)).Text;
Session["manage"] = selectedID.ToString();
//Response.Write(“Original message :”+selectedText);
Page.Response.Redirect(“payrollfeature.aspx”);
}

protected void delete_Click(object sender, EventArgs e)
{
try
{
con.Open();
//string sql = “SELECT count(*)as rows FROM FK_TBLUSER where NAME=’” + struser + “‘”;
}
catch (Exception e1)
{
Page.Response.Write(“Error in Delete : ” + e1);
}
finally { con.Close(); }
}//end of delete_click

protected void GridView_account_RowCommand(object sender, GridViewCommandEventArgs e)
{
ValidationCode result;
objCon = new ConnectionClass();
con = new OdbcConnection();
con = objCon.Connect_thru_config();

if (e.CommandName.Equals(“AddNew”))
{
TextBox name = (TextBox)GridView_account.FooterRow.FindControl(“txt_newname”);
TextBox passowrd = (TextBox)GridView_account.FooterRow.FindControl(“txt_newpassword”);
TextBox email = (TextBox)GridView_account.FooterRow.FindControl(“txt_newemail”);
passowrd.Text = “11111″;
if (name.Text == “”)
{
Page.Response.Write(“Please enter User name”);
}
else if (email.Text == “”)
{
Page.Response.Write(“Please enter Email address “);
}
else
{
int valid = checkuser(name.Text);
if (valid >= 1)
{
Page.Response.Write(“<b><font-weight: bold font-color:red >User already exists</font></b>” + valid);
}
else
{
result = CreateNewLogin(name.Text, passowrd.Text, email.Text);
if (result.Equals(“LoginCreated”))
{
Page.Response.Write(“Login has been created sucessfully :” + result);
Page.Response.Write(“<b>Welcome :<font color=\”blue\”>Login has been successfully created</font></b>”);
}
else
Page.Response.Write(“UnSuccessful: ” + result);
fillgridview();
}
}//
}
}//

protected void GridView_account_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView_account.EditIndex = e.NewEditIndex;
fillgridview();
}//

protected void GridView_account_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView_account.EditIndex = -1;
fillgridview();
}//

protected void GridView_account_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label accid = (Label)GridView_account.Rows[e.RowIndex].FindControl(“label_accid”);
TextBox name = (TextBox)GridView_account.Rows[e.RowIndex].FindControl(“txt_name”);
//TextBox passowrd = (TextBox)GridView_account.FooterRow.FindControl(“txt_password”);
objCon = new ConnectionClass();
con = new OdbcConnection();
con = objCon.Connect_thru_config();
con.Open();
string updateQuery = “update FK_TBLUSER set NAME=’” + name.Text + ‘where CID=’” + accid.Text
+ “‘”;
OdbcCommand updatecmd = new OdbcCommand(updateQuery, con);
updatecmd.CommandType = CommandType.Text;
updatecmd.ExecuteNonQuery();
con.Close();
GridView_account.EditIndex = -1;
fillgridview();
}//

protected void GridView_account_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string a = GridView_account.DataKeys[e.RowIndex].Values[0].ToString();
objCon = new ConnectionClass();
con = new OdbcConnection();
con = objCon.Connect_thru_config();
try
{
con.Open();
string deletequery = “delete from FK_TBLUSER where CID=’” + a.ToString() + “‘”;
OdbcCommand delcmd = new OdbcCommand(deletequery, con);
delcmd.ExecuteNonQuery();
}
catch (Exception e1)
{
Page.Response.Write(“Can not delete : ” + e1);
}
finally
{
con.Close();
}
GridView_account.EditIndex = -1;
fillgridview();
}//

public ValidationCode CreateNewLogin(string strLogin, int intParent, int strType, string strPassword)
{
//Create a connection
ConnectionClass conobj = new ConnectionClass();
con = new OdbcConnection();
con = conobj.Connect_thru_config();
con.Open();
// Create a command object for the query
Page.Response.Write(“Before SQL”);
string strSQL = “INSERT INTO FK_TBLUSER (NAME,PASSWORD) ” + “VALUES(?,?)”;
Page.Response.Write(“After SQL”);
OdbcCommand objCmd = new OdbcCommand(strSQL, con);
OdbcParameter paramUsername;
paramUsername = new OdbcParameter(“@Username”, OdbcType.VarChar, 50);
paramUsername.Value = strLogin;
objCmd.Parameters.Add(paramUsername);
//for Password parameters
//Encrypt the password

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] hashedBytes;
UTF8Encoding encoder = new UTF8Encoding();
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(strPassword));
OdbcParameter paramPwd;
paramPwd = new OdbcParameter(“@Password”, OdbcType.Binary, 16);
paramPwd.Value = hashedBytes;
objCmd.Parameters.Add(paramPwd);
//for User Name parameters
OdbcParameter paramUsermail;
paramUsermail = new OdbcParameter(“@Usermail”, OdbcType.VarChar, 50);
paramUsermail.Value = strEmail;
objCmd.Parameters.Add(paramUsermail);
objCmd.ExecuteNonQuery();
con.Close();
return ValidationCode.LoginCreated;
}//end of CreateNewLogin


// to check user exist or not
public int checkuser(string struser)
{
ConnectionClass conobj = new ConnectionClass();
con = new OdbcConnection();
con = conobj.Connect_thru_config();
int countuser = 0;
con.Open();
string sql = “SELECT count(*)as rows FROM FK_TBLUSER where NAME=’” + struser + “‘”;
cmd = new OdbcCommand(sql, con);
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
countuser = Convert.ToInt32(myreader["rows"]);
//Page.Response.Write(result);
}
Page.Response.Write(“Value of Result :” + countuser + “<br>”);
myreader.Close();
con.Close();
return countuser;
}

Table Structure

CREATE TABLE [FK_TBLUSER] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[NAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PASSWORD] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
CONSTRAINT [FK_TBLUSER_PK] PRIMARY KEY  CLUSTERED
(
[CID]
)  ON [PRIMARY]
) ON [PRIMARY]
GO

Please leave your comment if this post was helpful, I am also ready to hear criticism

Posted in DATAGRID AND GRIDVIEW | 15 Comments »