Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default exporting from sql query results to a excel workbook

Hi,

I have managed to get an
example:(http://support.microsoft.com/kb/307029/en-us) working that exports
from an example mdb file called northwind but In my project I have an sql
database and I have tried to change the connectionstring to the mdf database
but I recieve this error
"Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done." what do I need to change to get
export working from my own database.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default exporting from sql query results to a excel workbook

Show your code.

Tim


"OceanMist" wrote in message
...
Hi,

I have managed to get an
example:(http://support.microsoft.com/kb/307029/en-us) working that
exports
from an example mdb file called northwind but In my project I have an sql
database and I have tried to change the connectionstring to the mdf
database
but I recieve this error
"Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done." what do I need to change to get
export working from my own database.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default exporting from sql query results to a excel workbook

Here is the connection string
private string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ ".\\SQLEXPRESS;AttachDbFilename=C:\\Documents
and Settings\\Conor\\My Documents\\Visual Studio
2005\\Projects\\CallManSys19Jul\\CMS\\CMSDatabase. mdf;Integrated
Security=True;User Instance=True";

and in the button code

private void AnalyseButton_Click(object sender, EventArgs e)
{
OleDbConnection objConn = new OleDbConnection(strConn);
try
{
//Fill a dataset with records from the Customers table.
OleDbCommand objCmd = new OleDbCommand(
"Select Call_id, name, dept, "
+ "location, Resolved_by, Problem_Type from Call
Reports", objConn);
//"Select CustomerID, CompanyName, ContactName, "
//+ "Country, Phone from Customers", objConn);
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
objAdapter.SelectCommand = objCmd;
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset);


//Create the FileStream to write with.
System.IO.FileStream fs = new System.IO.FileStream(
"C:\\Call Reports.xml", System.IO.FileMode.Create);

//Create an XmlTextWriter for the FileStream.
System.Xml.XmlTextWriter xtw = new
System.Xml.XmlTextWriter(
fs, System.Text.Encoding.Unicode);

//Add processing instructions to the beginning of the
XML file, one
//of which indicates a style sheet.
// xtw.WriteProcessingInstruction("xml", "version='1.0'");
// xtw.WriteProcessingInstruction("xml-stylesheet",
// "type='text/xsl' href='Call Reports.xsl'");

//Write the XML from the dataset to the file.
objDataset.WriteXml(xtw);
xtw.Close();

//Close the database connection.
objConn.Close();

catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}

}


I hope this is sufficient code



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access query results to Excel piano banger Excel Discussion (Misc queries) 4 December 8th 06 09:32 AM
Exporting from Excel to CSV results in wrong characters Mark B Excel Discussion (Misc queries) 0 September 13th 06 08:39 PM
Mess-up When Exporting to an Excel in Query Analyzer Emily[_3_] Excel Programming 1 August 24th 06 06:22 AM
Complex Query Not Able To Get Results in Excel cb22 Excel Programming 2 January 19th 06 01:47 AM
Error message in Excel after exporting Access query to Excel Romi Excel Discussion (Misc queries) 0 June 6th 05 02:53 PM


All times are GMT +1. The time now is 02:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"