exporting from sql query results to a excel workbook

G

Guest

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top