We have to create a excel as a database.
Step 1 : Open Excel sheet and enter data's
Step 2 : Select the data's which u want.
Step 3 : Click Insert tab->Name->Define
Step 4 : Give the name for the selected data's
pgeExcel.cs
Now we display the excel database in a gridview which we created.
OleDbDataAdapter da;
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=f:/Book1.xls;Extended Properties=Excel 8.0;");
con.open();
da = new OleDbDataAdapter("select * from emp", con);//emp is the name given in excel sheet
DataSet ds=new DataSet();
da.Fill(ds,"emp");
GridView1.DataSource=ds;
GridView1.DataBind();
Copy Data From Excel to GridView
Thursday, September 27, 2007 | 0 Comments
Connection String For ASP.NET using Oracle
// Data Provider for OLE DB
using System.Data.OleDb
OleDbConnection oracleConn = new OleDbConnection("Provider= \"OraOLEDB.Oracle.1\";User ID=scott;Password=tiger;Data Source=yourSource; Extended Properties="";Persist Security Info=False";);
//Data Provider for ODBC
using System.Data.Odbc
OdbcConnection oracleConn = new OdbcConnection("DSN=odbcName ;UID=scott;PWD=tiger;DRIVER={Microsoft ODBC for Oracle};
SERVER=oracleServerNameOr IPAddress;";);
//Data Provider for Oracle Client
using System.Data.OracleClient
OracleConnection oracleConn = new OracleConnection("user id=scott;
data source=oracleSN;password=tiger";);
Tuesday, September 25, 2007 | 0 Comments
Fill DropDownList with first Item as Select/All
Coding :
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\PrjAspnet\\test1\\db1.mdb");
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter("select empid,empname from emp", con);
DataTable dt = new DataTable();
da.Fill(dt); // fill dropdown from database
dr = dt.NewRow();
dr[0] = "0"; //DataValueField
dr[1] = "-------- Select --------"; //or dr[1] = "All" // DataTextField
dt.Rows.InsertAt(dr, 0); // give the postion where you want item to be
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "empname";
DropDownList1.DataValueField = "empid";
DropDownList1.DataBind();
}
Or
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\PrjAspnet\\test1\\db1.mdb");
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter("select empid,empname from emp", con);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "empname";
DropDownList1.DataValueField = "empid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "--Select--");
DropDownList1.Items.FindByText("--Select--").Value = "0";
}
Wednesday, September 19, 2007 | 0 Comments
Script to Make TextBox to Enter Only NUMBER
<script language=javascript>
function NumberOnly()
{
var keyCode = event.keyCode;
if(keyCode > 47 && keyCode < 58)
{
return true;
}
else
{
return false;
}
}
</script>
<asp:TextBox ID="txt" runat="server" onkeypress="return NumberOnly()"></asp:TextBox>
Place the Script in the keyPress Event of the textbox to see the result.
Monday, September 17, 2007 | 0 Comments
To write a Script in server side in Asp.net
Syntax :
ScriptManager.RegisterStartupScript(Control control,type type,string Key,string Script,bool addScriptTags)
Example:
string s = "alert('Hello')";
ScriptManager.RegisterStartupScript(this, this.GetType(), "Hello", s, true);
If you give the script tag in the string s then give addScriptTags to false.
ScriptManager is a class inside System.Web.UI
As a result a alert box with 'hello' pops up, where you place this line.
Wednesday, September 12, 2007 | 0 Comments
Authorization
Authorization is to determine whether an identity should be granted the requested type of access to a given resource.
users: Assign a list of users to be granted or denied access
Roles: Assign a list of roles to be granted or denied access
<allow users="Don , Jim" roles="Admins" /> //Allow only two user Don,Jim
<deny users="*" /> //Restrict all other user
</authorization>
//Allow All the user to access
<allow users="*" />
</authorization>
* Refers to all identities
? Refers to the anonymous identity
Tuesday, September 11, 2007 | 0 Comments
SEARCH ALL FLOPPY,CD AND HARD DISK DRIVES
//search all floppy,cd and hard disk drives available in our PC
//its varies from system to system
for(char Ch='A';Ch<='Z';Ch++) { string Dir = Ch + @":\"; if (Directory.Exists(Dir)) {
disksListBox.Items.Add( Ch+ @":" ); //Add into ListBox
}
}
Tuesday, September 04, 2007 | 0 Comments
COPY AND PASTE THE DATA USING CLIPBOARD
//copy the data using Clipboard
Clipboard.SetDataObject(textBox1.SelectedText,true);
//paste the data using Clipboard
IDataObject iData = Clipboard.GetDataObject();
//Determine whether the data is in a format you can use.
if(iData.GetDataPresent(DataFormats.Text))
{
textBox1.SelectedText =(String)iData.GetData(DataFormats.Text); //display it in a text box.
}
Tuesday, September 04, 2007 | 0 Comments
GET THE USER NAME IN C# FOR NT AUTHENTICATION
//Declare the Header File
using System.Security.Principal;
string a;
a=System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
//Above Statement,opens us up to more than just the current user.
MessageBox.Show(a.ToString());
Monday, September 03, 2007 | 0 Comments
TO EXECUTE THE .exe FILE IN RUNTIME
System.Diagnostics.Process.Start("calc");
System.Diagnostics.Process.Start("f:\\start.exe");
Sunday, September 02, 2007 | 0 Comments
WRITE THE DATA INTO FILE
using(StreamWriter sr=new StreamWriter("F:\\out.txt"))
{
sw.write("Have a nice day");
Response.write("saved");
}
Sunday, September 02, 2007 | 0 Comments
READ THE DATA FROM FILE
using(StreamReader sr=new StreamReader("h:\\appl.txt"))
{
while(sr.ReadLine()!=null)
{
string s;
s=sr.ReadLine();
ListBox1.Items.Add(s);
}
}
Sunday, September 02, 2007 | 0 Comments