Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2004, 08:53 AM
Authorized User
 
Join Date: Aug 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Alcapone
Default Fill listbox from excel sheet

Hi,

I use this code to fill a listbox from an excel sheet

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=C:\\MyExcel.xls;" +
"Extended Properties=" + (char)34 + "Excel 8.0;HDR=Yes;" + (char)34);
string Statement = ("SELECT * FROM [MatterNumber$] WHERE matter <> '' ");
OleDbCommand cmd = new OleDbCommand(Statement, conn);
try
   {
    conn.Open();
    OleDbDataReader myReader = cmd.ExecuteReader();
while(myReader.Read())
    {
    listBox1.Items.Add(myReader.GetString(0));
    }
    }
catch(OleDbException ex)
    {
       MessageBox.Show(ex.Message);
    }
conn.Close();

When i run the code i get the error message "Data type mismatch in criteria expression"

Anybody have an idea what am doing wrong

Thanks!
 
Old December 19th, 2004, 07:00 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My guess would be how Excel deals with empty values. The WHERE clause in your SQL could be causing the problem.

Try just running SELECT * FROM [MatterNumber$]. That should run and if so you might need WHERE matter IS NULL, but I've never done this before so I'm not sure how Excel deals with it.


Kep.
 
Old December 22nd, 2004, 04:31 PM
Authorized User
 
Join Date: Aug 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Alcapone
Default

The problem was that the code i wrote works for excel xp but not for 2003. Thanks any way!

Regards,
Martijn





Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox in Excel Sheet anup.bihani Excel VBA 1 November 16th, 2006 10:29 AM
Excel Sheet Security kotaiah Excel VBA 0 September 12th, 2006 10:46 AM
write multi-sheet Excel w/o Excel.Application manmoth Classic ASP Components 2 November 22nd, 2005 10:56 AM
Fill color in Excel Cell Anantsharma Excel VBA 14 October 25th, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.