In MySQL table I need check this condition using C# in aspnet on DataSet :
if (A < 0.1 && B > 1 && (C >= 1 && C <= 4))
When all conditions are true I need to print the value on aspx page.
I have tried without success this code :
Double[] A = dt.Rows[0]["A"].Split(',');
Double[] B = dt.Rows[0]["B"].Split(',');
Double[] C = dt.Rows[0]["C"].Split(',');
long AC = A.Where(x => x < 0.1).Count();
long BC = B.Where(x => x > 1).Count();
long CC = C.Where(x => x >= 1 && x <= 4).Count();
if((AC == 1) && (BC == 1) && (CC == 1)
{
//Print
}
But the error is :
C# 'object' does not contain a definition for “Split”
My table below and column A, B and C are setting as Decimal 10,2 value.
+---+-------+------+
| A | B | C |
+---+-------+------+
| 0 | 16,11 | 3,08 |
+---+-------+------+
How can I resolve this?
Edit #01
I can't print the value ...
Double[] A = dt.Rows[0]["A"].ToString().Split(',').Select(double.Parse).ToArray();
string str = A.ToString();
Response.Write(str);
Edit #02
This is my table ( first 10 rows ) :
+------+------+------+
| A | B | C |
+------+------+------+
| 0,59 | 1,54 | 1 |
| 6,77 | 0,13 | 1,3 |
| 1 | 1,26 | 1 |
| 0,67 | 0,18 | 1,5 |
| 1 | 0,13 | 0,1 |
| 1 | 0,38 | 0,08 |
| 0,5 | 0,17 | 4 |
| 6,73 | 0,29 | 15 |
| 0 | 16,1 | 3,8 |
| 0,13 | 0,8 | 8 |
+------+------+------+
I expected this result of printing :
A >>> 0,59 6,77 1 0,67 1 1 0,5 6,73 0 0,13
B >>> 1,54 0,13 1,26 ...
C >>> 1 1,3 1 ...
But instead in output I have :
A >>> 1 0
B >>> 1 0
C >>> 1 0
I use your suggestion on this code :
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
Double[] A = dt.Rows[0]["A"].ToString().Split(',').Select(double.Parse).ToArray();
Double[] B = dt.Rows[0]["B"].ToString().Split(',').Select(double.Parse).ToArray();
Double[] C = dt.Rows[0]["C"].ToString().Split(',').Select(double.Parse).ToArray();
Response.Write("A >>> " + String.Join(" ", A.Select(a => a.ToString()).ToArray()) + "<br /><br />");
Response.Write("B >>> " + String.Join(" ", B.Select(b => b.ToString()).ToArray()) + "<br /><br />");
Response.Write("C >>> " + String.Join(" ", C.Select(c => c.ToString()).ToArray()) + "<br /><br />");
}
}
}
Edit #03
Error:
The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments
Code
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
var rows = dt.Rows.OfType<DataRow>().ToArray();
Response.Write("A >>> " + string.Join(' ', rows.Select(a => a[0].ToString())) + "<br /><br />");
Response.Write("B >>> " + string.Join(' ', rows.Select(b => b[1].ToString())) + "<br /><br />");
Response.Write("C >>> " + string.Join(' ', rows.Select(c => c[2].ToString())) + "<br /><br />");
}
Edit #04
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
DataSet ds = new DataSet("Test");
DataTable table = ds.Tables.Add("TestTable");
table.Columns.Add("A");
table.Columns.Add("B");
table.Columns.Add("C");
DataRow dr = table.NewRow();
dr["A"] = "0,59";
dr["B"] = "1,54";
dr["C"] = "1";
table.Rows.Add(dr);
DataRow dr2 = table.NewRow();
dr2["A"] = "6,77";
dr2["B"] = "0,13";
dr2["C"] = "1,3";
table.Rows.Add(dr2);
DataTable dt = null;
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
var rows = table.Rows.OfType<DataRow>().ToArray();
string A = ("A >>> " + string.Join(' ', rows.Select(a => a[0].ToString())) + "<br /><br />");
string B = ("B >>> " + string.Join(' ', rows.Select(b => b[1].ToString())) + "<br /><br />");
string C = ("C >>> " + string.Join(' ', rows.Select(c => c[2].ToString())) + "<br /><br />");
Console.WriteLine(A);
Console.WriteLine(B);
Console.WriteLine(C);
}
Console.ReadKey();
}
}
}
These are lines of error :
Error:
The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments