ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   exporting from sql query results to a excel workbook (https://www.excelbanter.com/excel-programming/393734-exporting-sql-query-results-excel-workbook.html)

oceanmist

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.

Tim Williams

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.




oceanmist

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





All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com