Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have one excel sheet and i am binding my excelsheet to gridview.no iam checking specialcharacters .i am getting but it displays last cell two times.And one more thing i want to display cell number also.my code is
C++
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();
        }

C++
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>");
           }
Posted
Updated 18-Jul-11 20:34pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Jul-11 2:41am    
So? What's the question? There are not "special characters". Which ones are "special", in your opinion?
The code belongs to dumpster. Look at switch 1, 2, 3... (sigh).
--SA
LakshmiNarayana Nalluri 19-Jul-11 2:44am    
i am getting ouput but it is not getting cell number correctly. and it displays last special field twice.how can i resolve that two problems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900