SqlConnection cn = new SqlConnection("server=LakshmiNarayana;uid=sa;pwd=cybage@123;database=narayana"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } public void bind() { string cnstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\\Book2.xls;" + "Extended Properties=Excel 8.0"; OleDbConnection oledbConn = new OleDbConnection(cnstr); string strSQL = "SELECT * FROM [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(strSQL, oledbConn); DataTable dt = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); }
protected void Button1_Click(object sender, EventArgs e) { string cnstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\\Book2.xls;" + "Extended Properties=Excel 8.0"; OleDbConnection oledbConn = new OleDbConnection(cnstr); string strSQL = "SELECT * FROM [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(strSQL, oledbConn); DataTable dt = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { string str = dt.Rows[i][j].ToString(); string str1 = "#$%^@"; for (int k = 0; k < str1.Length; k++) { for (int l = 0; l < str.Length; l++) { if (str1[k] == str[l]) { switch (j) { case 1: s = "B"; break; case 2: s = "C"; break; case 3: s = "D"; break; case 4: s = "E"; break; default: s = "Z"; break; } Page.RegisterStartupScript("<script>", "<script>alert('" + s + (i+1).ToString() + "')</script>"); Response.Write(dt.Rows[i][j].ToString()); } } } } Response.Write("<br>"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)