|
Excel.Application ExcelApp = new Excel.ApplicationClass();
ExcelApp.Visible = false;
String WorkbookPath = filename;
Excel.Workbook ExcelWorkbook = ExcelApp.Workbooks.Open(WorkbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Worksheet Sheet = (Excel.Worksheet)ExcelWorkbook.Sheets[1];
DataTable newTable = new DataTable();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties= Excel 8.0";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + Sheet + "$]", conn);
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(newTable);
dataGridView1.DataSource = newTable;
I am using this code to read an excel file and save the data in a datatable ....
I am getting this error "System.__ComObject$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long." and the error pointer comes on the second last line of the code ... can neone help
|
|
|
|
|
You are building your SQL string by concatenating the object Sheet. This object is of type Excel.Worksheet - which is not a string. Thus, as with all objects, it is calling it's ToString() method to obtain a string value it can concatenate with the rest of the SQL string. Since Excel.Worksheet is a COM Object, it's ToString is returning "System.__ComObject". You'll need to obtain the actual text name of the worksheet and use that to build the SQL string.
|
|
|
|
|
Thankyou very much ... the answer was not only precise but was very well explained
|
|
|
|
|
You may also want to take a look at OleDbConnection.GetSchema (Google it to find the MSDN documentation link). This will allow you to directly obtain schema information for the Excel file. The schema is returned as a DataSet containing DataTables for a variety of entities. One of these DataTables will contain a list of table names (which are the Excel worksheet names you'll use in your queries). This will allow you to avoid using COM automation entirely (ie. Excel Object library) to obtain the list of Worksheets. The benefit: no dependency on Excel object library DLLs, registration, versioning, etc... all the headaches that come with COM automation.
|
|
|
|
|
Hi all,
if someone forgets there password for login to a website, i would like to send them an email with there username and password by quering the database.
Can any one advice me on the C# code that is used for sending email to a user?
Thank you in advance.
|
|
|
|
|
If you search this site for an article called 'how to use google', you'll find that I both answer your question, and the underlying question that caused you to need to ask this.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi Christain,
Thank you for your response.
Can you at least learn to be polite?
Any ways I have the Answer :
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(sSMTPUser, sSMTPPass);
SmtpClient emailClient = new SmtpClient("smtp.gmail.com",587);
The 587 works with some mail Client but not with others like Gmail, etc...
|
|
|
|
|
He is being polite, and you're being lazy. You can find out what port Google expects by Googling for "SMTP port gmail".
Good luck
I are troll
|
|
|
|
|
kibromg wrote: Can you at least learn to be polite?
Watch your tone there, Christian Graus has been a member at codeproject for years, with over 50,000 posts and 30 articles, his Fixture/Legend status has been earned.
You are a firstly and obviously a beginner and new to programming, you're putting in NO effort to make your system functional other then expecting your work handed to you.
I'll be less polite then others, get the f*** off your ass and go learn to use Google, and if you can't find your answer there then guess what, it's time to find a different f***ing profession, one that is more suited to your (lack of) intelligence.
How's that for polite, buddy?
|
|
|
|
|
EliottA wrote: How's that for polite, buddy?
Not much, I'm afraid.
However it is pretty clear, except for some asterisks.
Do you really need 27 letters in your alphabet?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I could have circumvented then filter, but I didn't feel it appropriate.
Those responses truly get to me, especially when geared towards people with high post/article counts who have contributed more then enough for others. I knew zilch about programming before I stumbled my butt onto this site, and learned from various tutorials and posts before I began to post myself.
So retorts like that, insulting from people from whom I've directly (or indirectly) learned off of comes as a direct insult to me.
|
|
|
|
|
Yes, you and I both don't like what was said.
However, if I would want to call someone impolite, I would still try and do so in a polite way if such is possible at all.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
I have a class called "Card" (as in a deck of cards), which extends the PictureBox class. Now the picturebox is the size of the image (150X215). When you mouse over the card it "hovers" (its Y location decreases 20 pixels) and is supposed to show part of the card underneath it. However this does not happen. See this picture: http://img199.imageshack.us/i/cardsj.jpg/[^]
I've done this in the OnLoad event of the Card class:
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
But it doesn't work (as you can see in the picture). I found this article: http://www.codeproject.com/combobox/TransListBox.asp[^]
But how do I do this in C#?
BTW the images are transparent png's.
|
|
|
|
|
Using pictureboxes for this, is a little insane. Just draw your cards onto your form in your paint event.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I've changed it from PictureBox to Panel and added this:
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
pe.Graphics.DrawImage(this.card_image, new Point(0, 0));
}
But it's still not transparent. Do you want to look at my code?
|
|
|
|
|
No, I want you to do what I suggested. DON'T put the images inside a control, draw them on your form directly, in your paint event.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: Using pictureboxes for this, is a little insane
ftfy
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
hi i am working on an application that automates a website, my work is to upload a file but it is not clear to me how i can get the browse folder dialog box event(on clicking the browse button).
|
|
|
|
|
More clarity in your question would be helpful.
|
|
|
|
|
Kindly some one help me out how to find the Received time in mail & Sender mail address.
I had used OutlookStorage where sender mail & Received time property is not available.
kindly some one help me urgently
|
|
|
|
|
sajan_f wrote: help me urgently
This is very rude, it may be urgent to you but not to us.
only two letters away from being an asset
|
|
|
|
|
Hi Guys,
I am DataReader to get data from DB and dump the data into Excel sheet using XML's.
but,as the data reader holds the data for entire row, i am unable to get the data for other cells.
from datareader, i am getting <b>txt1, dt1, dt2 </b>in a single row, but i have to export this data to excel in multiple rows,
like
<pre>if (CurTaskNode.ReadFormat == "ColumnbyColumn")
{ for (int iCol = 0; iCol < lengthHeader; iCol++)
{
// Checking whether the Header data exists or not
if (CurTaskNode.HeaderData[minCol] != "")
{
//if (!(excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol]).Locked)
//{
// Assigning the Value from readerto to the particular cell in excel sheet
excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol] = values[iValueIndex];
iValueIndex++;
//}
}
minCol++;
}
minRow++;
}
</pre>
so, xml has 2 tasks namely projdata, projduration, so for the first task it should take the data and put in excel cell( 1,1 ) and in second task it should place it excel (10,2) and (10, 3)
< <Reference>
<SheetName>Setup_View</SheetName>
<TaskName>SubProjectName</TaskName>
<TaskName>ProjectDuration</TaskName>
</Reference> >
pleasee help me in modifying the code??
Thanks Ramm
|
|
|
|
|
hi guys
i want to read from a simulator (an clinical test device) which
is sending data on serial port , but i cant get correct data it shows junk characters ,
application works fine , simulator also shows correct output if connected with DockLight ,
any idea ?
thanks
regards ,
Tauseef A Khan
MCP Dotnet framework 2.0.
|
|
|
|
|
So you are saying that you can succesfully connect to the device and receive its data?
If so, what is your reason to think the data is not correct?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|