calebbaity
asked on
Need to Modify C# Console App code to send output to CSV file.
I need to modify a C# console application to output a SQL result set to a CSV file. Currently the application sends the output to a Text box (textXMLResult).
Current Visual Studio Solution:
XXXApiSample
-Service References
-Properties
-References
-app.config
-C# ExampleCode.cs
-FormApi.cs
-C# Program.cs
-C# UseCase.cs
-C# Utility.cs
C# Program.cs
FormApi.cs
What I want to do is send the output of the query to a CSV file prior to the Textbox (textXMLResult). In part because the textbox has a MaxLength of 32767 and also to do additional work on the file result set.
Current Visual Studio Solution:
XXXApiSample
-Service References
-Properties
-References
-app.config
-C# ExampleCode.cs
-FormApi.cs
-C# Program.cs
-C# UseCase.cs
-C# Utility.cs
C# Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace XXXApiSample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormAPI());
}
}
}
FormApi.cs
...
private void buttonGetData_Click(object sender, EventArgs e)
{
this.textXMLResult.Text = "";
ExampleCode ec = new ExampleCode();
this.textXMLResult.Text = ec.GetData(this.textServiceUrl.Text,
this.textUserName.Text,
this.textPassword.Text,
this.textScreenName.Text,
this.textGetDataParams.Text);
}
...
What I want to do is send the output of the query to a CSV file prior to the Textbox (textXMLResult). In part because the textbox has a MaxLength of 32767 and also to do additional work on the file result set.
ASKER
Actually, no. This is new functionality that I am adding to the GetData method. CSV is not provided.
So I would appreciate any guidance you can provide.
Also, with the code above, I am left with the impression that this code would get inserted between
lines #4 and #5 in the buttonGetDate_Click() function; is that correct?
So I would appreciate any guidance you can provide.
Also, with the code above, I am left with the impression that this code would get inserted between
lines #4 and #5 in the buttonGetDate_Click() function; is that correct?
Yupp. To generate a CSV I will need some sample data that your method returns from database.
ASKER
I am working on getting a data dictionary. But, I don't have that yet.
But for the sake of argument; lets day I have fields as follows:
tblProspects
Field1- ID
Field2- Name (String 50)
Field3-DOB (date)
Field4-Age (number)
Field5-Comments (Text 500 characters)
Query: Select * from tblProspects;
With Output to CVS file and Textbox.
But for the sake of argument; lets day I have fields as follows:
tblProspects
Field1- ID
Field2- Name (String 50)
Field3-DOB (date)
Field4-Age (number)
Field5-Comments (Text 500 characters)
Query: Select * from tblProspects;
With Output to CVS file and Textbox.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes. Database connectivity has been verified. Its just that the database is currently empty.
So I will need to create dummy data to verify.
However, I think you have given me everything I need.
Thank You!
So I will need to create dummy data to verify.
However, I think you have given me everything I need.
Thank You!
ASKER
Excellent Help. Even provided reference. Thank You!!
You are welcome :)
Sorry was away for last few days :)
Sorry was away for last few days :)
Open in new window