Copy Data From Excel to GridView

Labels:

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

Connection String For ASP.NET using Oracle

Labels: ,

// 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";);

Fill DropDownList with first Item as Select/All

Labels:

when we want the first item of dropdownlist to be user defined which is binded from the database,we have to insert a new row in the dropdownlist at first postion and give the DataTextField as our requirement.

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";
}