|
my code is
string test = "";
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value != null && (bool)row.Cells[1].FormattedValue)
{
String idtoselect = row.Cells[0].Value.ToString();
try
{
string sql2 = "select NAME_Product from Product where Product.ID_Product = '"+idtoselect+"' ";
SqlCommand testcommand2 = new SqlCommand(sql2, conn);
rdr = testcommand2.ExecuteReader();
if (rdr.Read())
{
test = rdr["NAME_Product"].ToString();
}
rdr.Close();
try
{
CultureInfo ci = new CultureInfo("th-TH");
string sql = "SELECT * FROM Order1 where ID_Product = @ID AND DATE_Order BETWEEN @D1 AND @D2";
da = new SqlDataAdapter(sql, conn);
da.SelectCommand.Parameters.AddWithValue("@ID", idtoselect);
da.SelectCommand.Parameters.AddWithValue("@D1", dateTimePicker1.Value);
da.SelectCommand.Parameters.AddWithValue("@D2", dateTimePicker2.Value);
ds = new DataSet();
da.Fill(ds, "Order1");
chart1.DataSource = ds.Tables["Order1"];
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
chart1.Series.Add(test);
chart1.Series[test].ChartArea = "ChartArea1";
chart1.Series[test].BorderWidth = 4;
chart1.Series[test].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[test].YValueMembers += "QUANTITY_Order";
chart1.Series[test].XValueMember += "DATE_Order";
chart1.DataBind();
MessageBox.Show("test :" );
}
catch (Exception ex)
{
MessageBox.Show("test :" + ex);
}
}
catch
{
MessageBox.Show("Exception");
}
}
i want to select quantity(QUANTITY_Order) that have been sold to show on my chart
if i select only one product chart will be show with correct value but if i choose two product in my list box for compare with two product value of first product will be wrong and it copy value of second product
this's my demo interface
http://image.ohozaa.com/view/8146d
it will show all product in database to list box and datetimepicker1 for select start date to find quantity in database and datetimepicker2 for select finish date
then when i select two data in listbox and i use MessageBox.Show("test :" ); for break to show my chart
this picture will show value of first product
http://image.ohozaa.com/view/8146t
then when i click on messagebox will show second product
http://image.ohozaa.com/view/81473
then you can see the value of first product in blue line will change value like second product
this is my database on mysqlserver 2005
http://image.ohozaa.com/view/8147g
thank you for your answer to much
|
|
|
|
|
I don't know what kind of charting component you are using nor how it works, however
chart1.DataSource = ds.Tables["Order1"];
looks very suspicious to me: the last row selected will set the final value of DataSource, so I am not surprised all series shown refer to it.
The chart probably needs a single table that holds all the data, so each series can point to one column of that one table.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
thank you for all reply
now i'm try to use datatable but it have same problem
this is my code
datatb = new DataTable();
da.Fill(datatb);
chart1.DataSource = datatb;
i don't know why it's wrong
i really need your help i'm so new in c#
please
|
|
|
|
|
I would agree with Luc that a DataTable would be more use than a DataSet - if you only use one table, then there is no point in allowing for others.
But looking at your images, it looks right.
You have a limited range of dates, all of which fall within your start and end dates, and the graph looks right - assuming that you are only using an ID_product of 18 - your SELECT query will only return 3 rows (since I suspect the BETWEEN ignores the entry on the 29th because it is after the start of the day.
What did you expect it to look like?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
i try to use data table but it show same problem i don,t know what's wrong
|
|
|
|
|
As I said - from the data you showed, it looked right - what are you expecting to see?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
data in chart not like in my database
ID_Product = 14 have quantity 19 at(26/1/2555) ,1 at(28/1/2555) ,8 at(29/1/2555)
and
ID_Product = 18 have quantity 1 at(25/1/2555) ,1 at(27/1/2555) ,5 at(28/1/2555) and 3 at(29/1/2555)
but in chart why shown same value
please help me i'm stuck this problem for 2 day if i fix this ploblem it's will help for my project to much
|
|
|
|
|
Ah. Ok. that makes some sense.
You are using the same data values for each series: I'm not sure exactly what you need to do to fix that (I don't use the Microsoft Chart control) but it looks like a Chart control always takes it's data from a single table. This is taken and adapted from their example:
DataTable table = new System.Data.DataTable("Table1");
table.Columns.Add("Category", typeof(String));
table.Columns.Add("Value", typeof(Double));
table.Columns.Add("SecondValue", typeof(Double));
table.Rows.Add(new object[] { "Lost", 0, 17 });
table.Rows.Add(new object[] { "Very Good", 1, 5 });
table.Rows.Add(new object[] { "Good", 2, 0 });
table.Rows.Add(new object[] { "Unlikely", 3, 9 });
table.Rows.Add(new object[] { "Firm Order", 4, 1 });
DataSet set = new DataSet();
set.Tables.Add(table);
chart1.DataSource = set.Tables[0].DefaultView;
chart1.Series["Series1"].XValueMember = "Category";
chart1.Series["Series1"].YValueMembers = "Value";
chart1.Series.Add("Series2");
chart1.Series["Series2"].XValueMember = "Category";
chart1.Series["Series2"].YValueMembers = "SecondValue";
chart1.DataBind();
This does show two independent data plots, but from the same table. If it is the case that it always works from the same table, then you will have to either change your SELECT statement to return multiple columns (a PITA when you are dealing with user-selectable columns) or manually create a table, create the columns you need and add the data points to the appropriate columns. Not difficult, but fiddly and a bit messy. There may be an easier way, but I don't know what it is.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I would go for a single SQL statement that fills a single table with all required information, it would look somewhat like this:
select NAME_Product from Product where Product.ID_Product IN ( '"+str1+"' ", '"+str2+"' ", '"+str3+"' )
and you may want to append GROUP BY Product.ID_Product
So you would need:
- a loop to build the one SQL statement
- the execution of that SQL stm resulting in one DataTable
- a loop to tell your chart where to find all the data series
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
|
How can we write the long source of a program in
2 or 3 files and relate them together at build time.
|
|
|
|
|
|
I rather think he has five source-files (.cs) that should be linked to a single executable. The IDE does that for us
Bastard Programmer from Hell
|
|
|
|
|
The question (as with so many) is somewhat open to interpretation.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Yes, but the wording "two or three files" are a give-away.
..with everybody recommending on how to distribute classes over multiple files
Bastard Programmer from Hell
|
|
|
|
|
Which is why I made the suggestion that I did.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
better way is to ask for more information about the question.!!!
@faraz34 : what exactly you would like to achieve ? whats your problem ?
thanks
-Amit.
|
|
|
|
|
Not at all; I gave an answer which may be the right one. If not then OP can respond with more details.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
the ways of an MVP, you should treat with the greatest respect!
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
If you referring to writing classes with an extensive amount of code. Then I'd suggest you use the "partial" key word. That way you can spread your class over separate files. In each file you just call the full declaration of the class but with the partial key word. Eg;
public partial class Employee
{
public void DoWork()
{
}
}
public partial class Employee
{
public void GoToLunch()
{
}
}
http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx[^]
|
|
|
|
|
faraz34 wrote: How can we write the long source of a program in
2 or 3 files and relate them together at build time.
1. Design your application so that you can break the functionality into classes. Classes normally are rather small. This step has nothing to do with actually writing code.
2. Implement each class in a different file.
3. In C# you put all of the classes in a project which is then managed via a solution.
|
|
|
|
|
jschell wrote: 3. In C# you put all of the classes in a project which is then managed via a
solution.
You mean "in Visual Studio"; C# neither knows nor cares about projects and solutions.
|
|
|
|
|
csc /out:My.exe *.cs
Will compile all .cs files within that folder into My.exe. Snippet taken from MSDN[^].
Bastard Programmer from Hell
|
|
|
|
|
Yes, but I use /recurse:"*.cs"
|
|
|
|