Click here to Skip to main content
15,922,584 members
Home / Discussions / C#
   

C#

 
QuestionHow can we use Treeview inside DataGrid...? Pin
fmlove18-Jun-07 1:58
fmlove18-Jun-07 1:58 
AnswerRe: How can we use Treeview inside DataGrid...? Pin
\laddie18-Jun-07 19:13
\laddie18-Jun-07 19:13 
QuestionDelegate Events... Pin
Ylno18-Jun-07 1:51
Ylno18-Jun-07 1:51 
AnswerRe: Delegate Events... Pin
Ylno18-Jun-07 1:54
Ylno18-Jun-07 1:54 
Questiondatagridview in .NET Pin
neer118-Jun-07 1:43
neer118-Jun-07 1:43 
AnswerRe: datagridview in .NET Pin
lsconyer18-Jun-07 4:07
lsconyer18-Jun-07 4:07 
AnswerRe: datagridview in .NET Pin
I.explore.code18-Jun-07 19:54
I.explore.code18-Jun-07 19:54 
QuestionRead excel with diff datatypes in one column Pin
Suman Singh18-Jun-07 1:41
professionalSuman Singh18-Jun-07 1:41 
Hi All,

I have an excel file in this format, which I am trying to read using c#

04/05/2006 46 47
25 26 27
15 vgc 57


I am not able to read the values of row[1][0] and row[2][0], because in this column, the datatype of value in first row is date (04/05/2006).
In the same way, I am not able to read the row[2][1], because in this column, the datatype of value in first row is a numeric.

So, according to my perception, you need to have same datatype values in any particular column to read it in C#.

I am looking for any option to read these type of excel files with values of different datatypes in a particular column.

Any input will be highly appreciated.




FYI, This is the code snippet, I am using to read this excel file.

// Create connection string variable. Modify the "Data Source" parameter as appropriate for your environment.
String filePath = "D:\\ProjectInfo\\HU Mail\\test.xls";
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + filePath + "; Extended Properties=\"Excel 8.0;HDR=NO;\"";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

// Open connection with the database.
objConn.Open();

DataTable dt = null;


// Get the data table containg the schema guid.
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

String[] strSheetName = new String[dt.Rows.Count];
int i = 0;

// Add the sheet name to the string array.
foreach (DataRow row in dt.Rows)
{
strSheetName[i] = row["TABLE_NAME"].ToString();
i++;
}

string strComand = "select * from [" + strSheetName[2] + "]";
OleDbCommand objCmdSelect = new OleDbCommand(strComand, objConn);


// Create new OleDbDataAdapter that is used to build a DataSet based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
DataSet dsDeal = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(dsDeal, "LMPPrices");

for (int k = 0; k < dsDeal.Tables[0].Rows.Count; k++)
{
for (int j = 0; j < dsDeal.Tables[0].Columns.Count; j++)
{
Console.Write(dsDeal.Tables[0].Rows[k][j].ToString() + " -> ");
}
Console.WriteLine();
}

Console.ReadLine();

Best Regards,




AnswerRe: Read excel with diff datatypes in one column Pin
Jimmanuel18-Jun-07 2:48
Jimmanuel18-Jun-07 2:48 
AnswerRe: Read excel with diff datatypes in one column Pin
PIEBALDconsult18-Jun-07 8:49
mvePIEBALDconsult18-Jun-07 8:49 
AnswerRe: Read excel with diff datatypes in one column Pin
PIEBALDconsult18-Jun-07 8:59
mvePIEBALDconsult18-Jun-07 8:59 
QuestionLenghty operations Pin
Ira8418-Jun-07 1:10
Ira8418-Jun-07 1:10 
AnswerRe: Lenghty operations Pin
Stefan Prodan18-Jun-07 1:34
Stefan Prodan18-Jun-07 1:34 
AnswerRe: Lenghty operations Pin
Chintan.Desai18-Jun-07 3:28
Chintan.Desai18-Jun-07 3:28 
Questionparsing string using Regular Expression Pin
Blumen18-Jun-07 0:55
Blumen18-Jun-07 0:55 
AnswerRe: parsing string using Regular Expression Pin
Ed.Poore18-Jun-07 1:08
Ed.Poore18-Jun-07 1:08 
GeneralRe: parsing string using Regular Expression Pin
Blumen18-Jun-07 1:19
Blumen18-Jun-07 1:19 
GeneralRe: parsing string using Regular Expression Pin
Ed.Poore18-Jun-07 1:46
Ed.Poore18-Jun-07 1:46 
GeneralRe: parsing string using Regular Expression Pin
Blumen18-Jun-07 1:56
Blumen18-Jun-07 1:56 
GeneralRe: parsing string using Regular Expression Pin
Ed.Poore18-Jun-07 2:59
Ed.Poore18-Jun-07 2:59 
QuestionWindowsIdentity and related classes Pin
hamidkhan18-Jun-07 0:49
hamidkhan18-Jun-07 0:49 
QuestionRe: WindowsIdentity and related classes Pin
hamidkhan27-Jun-07 0:43
hamidkhan27-Jun-07 0:43 
QuestionExporting SQL Server 2005 Reporting Services reports to PDF Pin
khuzwayom18-Jun-07 0:19
khuzwayom18-Jun-07 0:19 
QuestionChecking for a keypress in console. Pin
jblouir18-Jun-07 0:13
jblouir18-Jun-07 0:13 
AnswerRe: Checking for a keypress in console. Pin
Nissim Salomon18-Jun-07 0:49
Nissim Salomon18-Jun-07 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.