Import data from excel cell to Textbox
-
Hi, I have an excel containing mail address For example: In excel "column B" i have a number of email address in B1,B2,B3.... Now the thing i want each email address from B1,B2,B3 into my TextBox1.Text. Am using vb.net with c# language. Can anyone send me the code or give me some idea?. Thanks in advance.
With Regards, Samson
-
Hi, I have an excel containing mail address For example: In excel "column B" i have a number of email address in B1,B2,B3.... Now the thing i want each email address from B1,B2,B3 into my TextBox1.Text. Am using vb.net with c# language. Can anyone send me the code or give me some idea?. Thanks in advance.
With Regards, Samson
If your spreadsheet is structured as a table in a database would be, you can use OleDb to connect to it, select the Column you want (select [column b] from $Sheet1), and then iterate through the collection to put stuff in the TextBox.
private void ConnectToExcel(string Location)
{
string ConnectionStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=\"Excel 8.0;HDR=YES\"", Location);
try
{
OleDbConnection Connection = new OleDbConnection(ConnectionStr);Connection.Open(); string SelectString = "select \[column b\] from $Sheet1"; OleDbCommand Command = new OleDbCommand(SelectString, Connection); OleDbDataReader olDbRead = Command.ExecuteNonQuery(); while (olDbRead.Read) { textBox1.Text += olDbRead\[0\].ToString(); } } catch{} finally{Connection.Close();}
}
samsonx wrote:
Am using vb.net with c# language.
Well you lost me here...
var question = (_2b || !(_2b));
-
If your spreadsheet is structured as a table in a database would be, you can use OleDb to connect to it, select the Column you want (select [column b] from $Sheet1), and then iterate through the collection to put stuff in the TextBox.
private void ConnectToExcel(string Location)
{
string ConnectionStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=\"Excel 8.0;HDR=YES\"", Location);
try
{
OleDbConnection Connection = new OleDbConnection(ConnectionStr);Connection.Open(); string SelectString = "select \[column b\] from $Sheet1"; OleDbCommand Command = new OleDbCommand(SelectString, Connection); OleDbDataReader olDbRead = Command.ExecuteNonQuery(); while (olDbRead.Read) { textBox1.Text += olDbRead\[0\].ToString(); } } catch{} finally{Connection.Close();}
}
samsonx wrote:
Am using vb.net with c# language.
Well you lost me here...
var question = (_2b || !(_2b));
hi weather this code works perfectly or not i don't know bcoz when i wanted to use oledb connection for excel sheet my program didnt accept that one.it says it as unrecognized format.how to connect excel sheet using oledb connection plz explain step by step.