Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Search Data in MS Excel File Using Asp.Net C#

$
0
0

Hi, I found this code on the internet but it doesn't work the way I want it to. You 
can only search for data by numbers, but I want to search for mixed data. Any suggestions?

Important Namespaces Used
-------------------------

using System.IO;
using System.Data.OleDb;


--------------------------

Search Button Click Event Coding
-------------------------

String ExcelPath = Server.MapPath("~/ExcelFile/StudentRecord.xlsx");
        OleDbConnection mycon = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0;Persist Security Info = False");
        mycon.Open();
        OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$] where rollno="+TextBox1.Text, mycon);
        OleDbDataReader dr = cmd.ExecuteReader();
        dr.Read();
        if (dr.HasRows)
        {
            // Response.Write("<br/>"+dr[0].ToString());
            TextBox2.Text =dr[1].ToString();
            TextBox3.Text = dr[2].ToString();
            TextBox4.Text = dr[3].ToString();
            Label3.Text = "";

        }
        else
        {
            Label3.Text = "No Particular Roll Number Found";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
        }

        mycon.Close();

---------------


Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>