|
Member 11221185 wrote: can u help me in coding Coding what! I have no idea of your data structure, the technology you are using. For all I know you may be coding for an iPhone.
We don't do the coding for you, you will get help if you show the code YOU have written and have a problem with.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Need a simple 2D graph library for C# console app. Thanks for any ideas.
sundownr
|
|
|
|
|
And?
Google not working today?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Google works fine and after trying a few libraries I did not find what I wanted... thus I asked for any ideas. I am trying SharpDX now but prefer something simpler. All I need to do is graph a series of voltages.
sundownr
|
|
|
|
|
Are you looking to manipulate a Charting library from a Console App: I mean what else could you do in the Console but read a file into some data structure(s), manipulate the data, call the library's facilities for creating a chart passing in the data, save the resulting output chart/graphic to a file ?
Why not create a WinForms app where you can preview the chart/image you create ?
«At the still point of the turning world. Neither flesh nor fleshless;
Neither from nor towards; at the still point, there the dance is
...
Neither ascent nor decline. Except for the point, the still point,
There would be no dance, and there is only the dance»
T.S. Elliot, The Four Quartets: "Burnt Norton"/xml>
modified 14-Nov-14 13:12pm.
|
|
|
|
|
Good description of graphing with the console. I asked this question myself and then posted my question. Unless the magic answer appears I guess I am stuck with Windows forms using DirectX. It sure would be nice to draw a simple graph with minimal code. Thanks for the thought... it clarified the issue. Note... I tried the "A simple C# library for graph plotting," here on the Code Project, but was unable to find the sample code the author referred to.
sundownr
|
|
|
|
|
Well, I can't see a downside to using a WinForm app, but what you want is what you want
Check this example out: [^]. It uses System.Windows.Forms.DataVisualization.Charting; from within a Console App.
I am under the impression there are many articles on Charting/Graphing in WinForms here on CP.
cheers, Bill
«The greater the social and cultural distances between people, the more magical the light can spring from their contact» Milan Kundera, "Testaments Trahis"
|
|
|
|
|
Thanks... I will give it a try.
sundownr
|
|
|
|
|
using System;
using System.Collections.Generic;
class Program {
static void Main( string[] args ) {
List<int> voltages = new List<int>() { 10, 4, 15, 7, 20 };
int n = 0;
foreach ( int voltage in voltages ) {
Console.WriteLine( "Voltage {0}: {1}", ++n, "".PadRight( voltage, '*' ) );
}
}
}
|
|
|
|
|
Thanks Gerry... I can use this. This is as simple as it can get.
sundownr
|
|
|
|
|
Hi All,
I am using Visual Studio 2008 to design windows form Application.
I created one form, that will Browse and select excel file and by clicking on Export button, all data will transfer to sql database.
But while debugging, it stop at code
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
For your review i am giving full code below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Common;
namespace CHD_CALL_REGISTER
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
string str = "Data Source=INLGM84MV1;Initial Catalog=CHD;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
}
public Form1()
{
InitializeComponent();
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\";
openFileDialog1.Title = "Browse Excel Files";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.DefaultExt = "xls";
openFileDialog1.Filter = "Excel file (*.xls)|*.xls";
openFileDialog1.RestoreDirectory = true;
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.SafeFileName;
buttonexport.Enabled = true;
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
buttonexport.Enabled = false;
}
}
private void buttonexport_Click(object sender, EventArgs e)
{
string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source" + textBox1.Text + ";Extended Properties\"Excel 8.0;HDR=YES\"";
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
{
bulkCopy.DestinationTableName = "EMP_TABLE";
bulkCopy.ColumnMappings.Add("EMPCODE", "EMPCODE");
bulkCopy.ColumnMappings.Add("EMP_NAME", "EMP_NAME");
bulkCopy.ColumnMappings.Add("BUSINESS_CODE", "BUSINESS_CODE");
bulkCopy.ColumnMappings.Add("JOIN_DT", "JOIN_DT");
bulkCopy.ColumnMappings.Add("HQ_NAME", "HQ_NAME");
bulkCopy.ColumnMappings.Add("ZONE_ID", "ZONE_ID");
bulkCopy.ColumnMappings.Add("DESIG", "DESIG");
bulkCopy.ColumnMappings.Add("BAND", "BAND");
bulkCopy.ColumnMappings.Add("DEPT_NAME", "DEPT_NAME");
bulkCopy.ColumnMappings.Add("EMP_STATUS", "EMP_STATUS");
bulkCopy.ColumnMappings.Add("SUP1", "SUP1");
bulkCopy.ColumnMappings.Add("SUP1NAME", "SUP1NAME");
bulkCopy.ColumnMappings.Add("SUP1HQ", "SUP1HQ");
bulkCopy.ColumnMappings.Add("SUP2", "SUP2");
bulkCopy.ColumnMappings.Add("SUP2NAME", "SUP2NAME");
bulkCopy.ColumnMappings.Add("SUP2HQ", "SUP2HQ");
bulkCopy.ColumnMappings.Add("SUP3", "SUP3");
bulkCopy.ColumnMappings.Add("SUP3NAME", "SUP3NAME");
bulkCopy.ColumnMappings.Add("SUP3HQ", "SUP3HQ");
bulkCopy.WriteToServer(dr);
MessageBox.Show("Data Exported To Sql Server Successfully");
}
}
}
}
}
}
Please help me...thanks in advance...
Vishal
|
|
|
|
|
Member 11134954 wrote: But while debugging, it stop at code After which point it will throw an exception with some valuable information.
Your connection-string is broken. It should read DataSource= . It'd be cleaner if you use a string.format to get your variable in there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Its get stop debug at below line.
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
|
|
|
|
|
And what does the exception say?
|
|
|
|
|
Yes, but that line is correct. Copy/paste below line, should at least give a new error.
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties\"Excel 8.0;HDR=YES\"", textBox1.Text);
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
After using your line/code. it still give same error but after i changed the line as below it proceed ahead.
string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\"";
Now it got stuck at line:
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
Exception message says:
The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.
|
|
|
|
|
That line again does not cause the problem; it is the SQL statement that is being executed that generates the error. Did you put the sheetname in brackets?
Find the code that says "SELECT .. FROM [Sheet1$]", that's where the problem is.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am using this line:
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
Does it seem to be invaline code?
|
|
|
|
|
Nope, looks correct. Same as the example here[^].
Is there a sheet with that name inside the workbook?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, sheet name is correct as Sheet1 in a excel file.
|
|
|
|
|
If you run the example code from the previous link, does it show the values?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That's what I would do, but there are other options as well.
|
|
|
|
|
When i export excel file with increase cell width because my data Not show completely into cell
How To implement In this code To Increase cell Width in cell File
My Export Excel Code Following :-
public ActionResult ExportToExcel(int MID)
{
MModule objModule = new MModule();
objModule.LoadModule(MID);
DatabaseObject objData = new DatabaseObject();
string file = DateTime.Now.Ticks + "_" + objModule.Title + ".xlsx";
System.IO.File.Copy(Server.MapPath("/Excel/Export/template.xlsx"), Server.MapPath("/Excel/Export/" + file));
string filename = Server.MapPath("/Excel/Export/" + file);
objData.Query = "SELECT * FROM " + objModule.TableName + "";
DataTable dtReport = objData.GetTable();
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Mode=ReadWrite;Extended Properties=\"Excel 12.0 Xml;Readonly=False;IMEX=0;\"");
con.Open();
System.Data.OleDb.OleDbCommand cmd = con.CreateCommand();
string tableString = "";
string ColString = "";
for (int i = 0; i < dtReport.Columns.Count; i++)
{
tableString += "[" + dtReport.Columns[i].Caption + "] varchar(255),";
ColString += "[" + dtReport.Columns[i].Caption + "],";
}
tableString = tableString.Substring(0, tableString.Length - 1);
try
{
ColString = ColString.Substring(0, ColString.Length - 1);
//***************** Create Excel Sheet Table *********************//
cmd.CommandText = "CREATE TABLE ["+ objModule.Title +"] ( " + tableString + ");";
cmd.ExecuteNonQuery();
string ValString = "";
for (int j = 0; j < dtReport.Rows.Count; j++)
{
ValString = "";
for (int i = 0; i < dtReport.Columns.Count; i++)
{
ValString += "'" + dtReport.Rows[j][i] + "',";
}
ValString = ValString.Substring(0, ValString.Length - 1);
cmd.CommandText = "Insert Into ["+ objModule.Title +"] (" + ColString + ") Values (" + ValString + ");";
cmd.ExecuteNonQuery();
}
cmd.Dispose();
con.Dispose();
con.Close();
Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = excelApplication.Workbooks.Open(filename,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
excelApplication.DisplayAlerts = false;
((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]).Delete();
workbook.Close(true, filename, null);
excelApplication.DisplayAlerts = true;
}
catch (Exception ex)
{
}
//return File(filename, "application/msexcel");
return File(filename, "application/x-excel", DateTime.Now.Ticks + "_Report.xlsx");
}
|
|
|
|
|
You don't increase the width of a cell. You can't do that in Excel and you can't do that in code.
You change the width of the COLUMN, not the cell.
C# Excel change column width[^]
|
|
|
|
|
How to create the windows application for Data recovery using c#.net which recovers all the deleted file from hard disk or removable disk
|
|
|
|
|