|
Filtering causes redrawing of all the rows and my color information is lost.
Of course, I need to use a hidden column for assigning an index code for each row, so I save the index color and load it. In this way, I can relocate those color information when using filtering.
|
|
|
|
|
I'm "guessing" that filtering is creating a "new" uncolored view; you might try and (re)color after applying the filter.
(It's a guess, so the troll need not get excited)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Did you say that I'm trolling?
I just want to get help and solve my problem. It's all.
|
|
|
|
|
No, he didn't call you a troll.
He's making a comment in an attempt to head off the trolls.
|
|
|
|
|
thank you for help. the previous explanation does make sense but when about instance how yo accesss it from other class? thank you
class felhasznalo
{
adatlista adat = new adatlista();
foreach (string elem adat.lista)
{
}
}
|
|
|
|
|
Every time you "new up" adatlista , you are creating a new list, separate from any other instance.
So, if you new up two lists and add items to the one of them, you will NOT see those items in the other list.
|
|
|
|
|
thank you for help. I don't want to create new list just access the existing one from other classes possibly with foreach or for loop, recoed by record, thank you.
|
|
|
|
|
You might want to try something like this:
class felhasznalo
{
private adatlista adat = new adatlista();
public adatlista items { return adat; }
} You can now access adat from outside your class.
The simple idea behind this concept is that you are exposing a property that allows external access to members of your class, but does it in a controlled manner. This is why I wrapped this in a property. You could, just make adatlista a public field and allow classes access to the public field but that's a separate debate.
modified 21-Apr-21 3:13am.
|
|
|
|
|
Hi
thank you for help.
In my modified instance I placed recordlist is a separate class to be able to access it from various classes but access issues occured. please help me to access the record list type thank you.
<pre>using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace metjelentes
{
class adatok
{
public string telepules = " ";
public string ido = " ";
public string szeliranyes_erosseg = " ";
public int homerseklet = 0;
}
class adatlista
{
public List<adatok> lista = new List<adatok>();
}
class beolvasas
{
public void beolvas()
{
string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
using (StreamReader sr =new StreamReader(olvas, Encoding.Default))
{
int db = 0;
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] elemek = sor.Split(' ');
adatlista.lista.Add(new adatok());
adatlista.lista[db].telepules=elemek[0];
adatlista.lista[db].ido = elemek[1];
adatlista.lista[db].szeliranyes_erosseg = elemek[2];
adatlista.lista[db].homerseklet = Int32.Parse(elemek[3]);
db++;
}
Random rd = new Random();
int rand_num = rd.Next(1, db);
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
|
|
|
|
adatlista is not a variable, it's a class:
class adatlista
{
public List<adatok> lista = new List<adatok>();
}
So you can't access it's list like this:
adatlista.lista.Add(new adatok());
Why not?
Because you need an instance of the class to work with ...
Let's ignore computers for a moment, and talk about cars.
We both have a car: the same make, the same model, the same colour, the same engine, the same age.
I give you a ride to the shops, and while in my car, you put your mobile phone in the glove box.
When you get home again, you need you mobile so you go to your car and open the glove box. Is your phone there?
No, of course not - it's in the glove box in my car. You know that it can only be accessed my opening my car, opening that glove box and reaching in for your phone, because you know that the two vehicles are separate instances of the particular class of black Mercedes A-class cars that they made in 2006.
You know that despite being outwardly identical, they are very different vehicles and that to do anything with them, you have to use the right instance. You want to drive to the airport, you take your car, not mine!
Classes and instances also matter in computers: Car is a class, but "your car" is a Car type variable which holds a Car class instance, "my car" is another Car type variable which holds a different Car class instance.
So you access the List in your adatlista class, you need to create an use a specific instance of that class:
adatlista adat = new adatlista();
adat.lista.Add(new adatok());
There is a way to get what you wrote to work, but ... it's probably something you haven't really covered yet: static classes - so I won't go into that. It's pretty important that you understand instances anyway!
Does that make sense?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
where view doesn't know about presenter, just raises events... presenter knows views controls (idk how to do the one where to make the presenter as if it was calling a console, for unit tests...)
1. should view contain ui logic, or all logic is in the presenter?
2. if view event is raised, should presenter call view's method or should presenter do the magic and tell view what control to change?
3. We're using a single form like sidebar with many usercontrols in the main panel, should presenters be separate from each other? even the main one?
4. When calling dispose to save resources, what happens to the presenter it's associated to? i get an error because the view is not there because deleted, check if null, create one with unity? what lifetime manager? should i dispose presenter too? how do i recreate it then if yes?
5. unity what lifetime manager is best? it's in the program.cs
thank you all in adv )
|
|
|
|
|
Hi
I try to load txt file data in record list in object but error msg stops code running. the error is below.
Severity Code Description Project File Line Suppression State
Error CS1955 Non-invocable member 'StreamReader' cannot be used like a method. metjelentes C:\Users\Dell\source\repos\metjelentes\metjelentes\Program.cs 21 Active
<pre>using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace metjelentes
{
class adatok
{
public string telepules = " ";
public string ido = " ";
public string szeliranyes_erosseg = " ";
public int homerseklet = 0;
}
class beolvasas
{
public void beolvas()
{
string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
{
List<adatok> lista = new List<adatok>();
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] elemek = sor.Split(' ');
lista.Add(new adatok());
}
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
|
|
|
|
Remove the ( between using and streamreader
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
You have this:
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
You have to "new up" a StreamReader to get an object for it:
using (StreamReader sr = new StreamReader(olvas, Encoding.Default))
|
|
|
|
|
In general, "Non-invocable member 'xxxxxx' cannot be used like a method" means you forgot the "new" in object creation.
Truth,
James
|
|
|
|
|
Hi everyone,
I created two kind of programming codes. The first one, I simply use HTTPListener class in .NET. The last one, I use a complex method with more than one thread to treat entering SOAP Request. For them, I return SOAP Response. These solutions runs perfectly within Windows Forms Application (of course, by moving the content of OnStart within the click of start button).
But, I have a big problem. The BeginGetContext of HTTPListener seems to be quiet and never react or trigger just within Windows Service. I don't think this issue is normal. These two algorithms runs without issue within Windows Forms Application. Naturally, if I start the Windows Service, the Windows Forms Application doesn't listen in same time. I only run one of them at once.
I have a valid self signed certificate. It runs under Windows Forms Application with no issue. I use the same for Windows Service, except with using OnStart and OnStop. Only at this moment, the situation is problematic.
I delete and add a SSL Certificate each time to be sure that I have loaded certificate within Windows.
I prefer to have simplicity with programming code. I am a fan to "keep it simple". I don't care to keep any of them. I want the best one.
Do you experiment this behavior in your life? I transfer many application from Windows Forms Application to Windows Service without any kind of issue in the past.
If I execute the DOS command : " telnet localhost 30010 ", the Windows Service listen really the port of communication 30010. But, the BeginGetContext didn't trigger to my function ListenerCallback or ContextReady like it is supposed to do.
I read basic documentations concerning HTTPListener class. I control the situation within Windows Forms Application. All methods runs perfectly. This is just if I use the Windows Service. The BeginGetContext doesn't react like it is supposed to react within Windows Service environment.
First one :
public partial class SOAPServer_Service : ServiceBase {
public string ErrorMessage = "";
private HttpListener Listener;
public SOAPServer_Service() {
InitializeComponent();
}
protected void OnStart(string[] args) {
try {
this.ErrorMessage = "";
string Port = "30010",
HashCertificat = "8f3146c64cb75a716a3543dfc10c2967acab9471",
URLEnvironment = "https://10.182.133.101:30010/WS/";
Process ProcessusDelete = new Process();
ProcessStartInfo StartInfoDelete = new ProcessStartInfo();
StartInfoDelete.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoDelete.FileName = "cmd.exe";
StartInfoDelete.Arguments = "/C C:\\Windows\\System32\\netsh http delete sslcert ipport=0.0.0.0:" + Port;
StartInfoDelete.Verb = "runas";
ProcessusDelete.StartInfo = StartInfoDelete;
ProcessusDelete.Start();
ProcessusDelete.WaitForExit(10000);
ProcessusDelete.Close();
Process ProcessusAdd = new Process();
ProcessStartInfo StartInfoAdd = new ProcessStartInfo();
StartInfoAdd.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoAdd.FileName = "cmd.exe";
StartInfoAdd.Arguments = "/C C:\\Windows\\System32\\netsh http add sslcert ipport=0.0.0.0:" + Port + " certhash=" + HashCertificat + " appid={e2eaacd9-92e6-43cc-b51c-7a7887149607}";
StartInfoAdd.Verb = "runas";
ProcessusAdd.StartInfo = StartInfoAdd;
ProcessusAdd.Start();
ProcessusAdd.WaitForExit(10000);
ProcessusAdd.Close();
if (HttpListener.IsSupported) {
if (this.Listener == null) {
this.Listener = new HttpListener();
}
this.Listener.Prefixes.Add(URLEnvironment);
this.Listener.Start();
IAsyncResult Result = this.Listener.BeginGetContext(new AsyncCallback(this.ListenerCallback), this.Listener);
} else {
this.ErrorMessage = "The operating system is not up to date!";
return false;
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStart.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected override void OnStop() {
try {
this.ErrorMessage = "";
if (this.Listener != null) {
this.Listener.Close();
this.Listener = null;
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStop.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
private void ListenerCallback(IAsyncResult Result) {
try {
string SOAPRequest = "",
SOAPResponse = "";
this.ErrorMessage = "";
HttpListenerContext Context = this.Listener.EndGetContext(Result);
HttpListenerRequest Request = Context.Request;
HttpListenerResponse Response = Context.Response;
if (Request.HasEntityBody) {
Stream S = Request.InputStream;
StreamReader SR = new StreamReader(S, Encoding.UTF8);
SOAPRequest = SR.ReadToEnd();
SR.Close();
S.Close();
using (FileStream fsIn = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Request_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swIn = new StreamWriter(fsIn, Encoding.UTF8)) {
swIn.WriteLine(SOAPRequest);
}
}
using (FileStream fsOut = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Response_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swOut = new StreamWriter(fsOut, Encoding.UTF8)) {
swOut.WriteLine(SOAPResponse);
}
}
byte[] byteSOAPResponse = UTF8Encoding.UTF8.GetBytes(SOAPResponse);
using (Stream StreamSender = Response.OutputStream) {
StreamSender.Write(byteSOAPResponse, 0, byteSOAPResponse.Length);
StreamSender.Close();
}
Response.Close();
Result = this.Listener.BeginGetContext(new AsyncCallback(this.ListenerCallback), this.Listener);
}
} catch (Exception E) {
this.ErrorMessage = this.RecupereException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ListenerCallback_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
swEntree.WriteLine("TryCatch : ");
swEntree.WriteLine(this.ErrorMessage);
}
}
return;
}
}
protected string RecupereException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
}
Second one :
public partial class SOAPServer_Service : ServiceBase {
public string ErrorMessage = "";
private int NbrThread = 5;
private SOAPServer_OSS ServerSOAP;
public SOAPServer_Service() {
InitializeComponent();
this.ServerSOAP = new SOAPServer_OSS(this.NbrThread);
}
protected void OnStart(string[] args) {
try {
this.ServerSOAP.Start();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStart.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected override void OnStop() {
try {
this.ServerSOAP.Stop();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStop.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected string GetCompleteException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
}
class SOAPServer_OSS : IDisposable {
private readonly HttpListener listener;
private readonly Thread listenerThread;
private readonly Thread[] thread;
private readonly ManualResetEvent state_listener,
state_queue;
private Queue<HttpListenerContext> queue;
public string port = "30010",
hashCertificat = "8f3146c64cb75a716a3543dfc10c2967acab9471";
public SOAPServer_OSS(int NbrThread) {
this.thread = new Thread[NbrThread];
this.queue = new Queue<HttpListenerContext>();
this.state_listener = new ManualResetEvent(false);
this.state_queue = new ManualResetEvent(false);
this.listener = new HttpListener();
this.listenerThread = new Thread(this.HandleRequests);
}
protected string GetCompleteException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
public void Start() {
try {
Process ProcessusDelete = new Process();
ProcessStartInfo StartInfoDelete = new ProcessStartInfo();
StartInfoDelete.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoDelete.FileName = "cmd.exe";
StartInfoDelete.Arguments = "/C C:\\Windows\\System32\\netsh http delete sslcert ipport=0.0.0.0:" + this.port;
StartInfoDelete.Verb = "runas";
ProcessusDelete.StartInfo = StartInfoDelete;
ProcessusDelete.Start();
ProcessusDelete.WaitForExit(10000);
ProcessusDelete.Close();
Process ProcessusAdd = new Process();
ProcessStartInfo StartInfoAdd = new ProcessStartInfo();
StartInfoAdd.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoAdd.FileName = "cmd.exe";
StartInfoAdd.Arguments = "/C C:\\Windows\\System32\\netsh http add sslcert ipport=0.0.0.0:" + this.port + " certhash=" + this.hashCertificat + " appid={e2eaacd9-92e6-43cc-b51c-7a7887149607}";
StartInfoAdd.Verb = "runas";
ProcessusAdd.StartInfo = StartInfoAdd;
ProcessusAdd.Start();
ProcessusAdd.WaitForExit(10000);
ProcessusAdd.Close();
this.listener.Prefixes.Add(String.Format(@"https://+:{0}/WS/", this.port));
this.listener.Start();
this.listenerThread.Start();
for (int i = 0; i < this.thread.Length; i++) {
this.thread[i] = new Thread(this.Worker);
this.thread[i].Name = "Thread_" + (i + 1).ToString();
this.thread[i].Start();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_SOAPServer_Start.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
public void Dispose() { this.Stop(); }
public void Stop() {
try {
this.state_listener.Set();
this.listenerThread.Join();
foreach (Thread T in this.thread) {
T.Join();
}
this.listener.Stop();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_Stop.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void HandleRequests() {
try {
while (this.listener.IsListening) {
var context = this.listener.BeginGetContext(this.ContextReady, null);
WaitHandle[] wait = new[] { this.state_listener, context.AsyncWaitHandle };
if (0 == WaitHandle.WaitAny(wait)) {
return;
}
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_HandleRequests.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void ContextReady(IAsyncResult ar) {
try {
lock (this.queue) {
this.queue.Enqueue(this.listener.EndGetContext(ar));
this.state_queue.Set();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ContextReady.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void Worker() {
try {
WaitHandle[] wait = new[] { this.state_queue, this.state_listener };
while (0 == WaitHandle.WaitAny(wait)) {
HttpListenerContext context;
lock (this.queue) {
if (this.queue.Count > 0) {
context = this.queue.Dequeue();
} else {
this.state_queue.Reset();
continue;
}
}
this.ProcessRequest(context);
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_Worker.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void ProcessRequest(HttpListenerContext Contexte) {
try {
HttpListenerRequest Request = Contexte.Request;
HttpListenerResponse Response = Contexte.Response;
if (Request.HasEntityBody) {
Stream S = Request.InputStream;
StreamReader SR = new StreamReader(S, Encoding.UTF8);
SOAPRequest = SR.ReadToEnd();
SR.Close();
S.Close();
using (FileStream fsIn = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Request_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swIn = new StreamWriter(fsIn, Encoding.UTF8)) {
swIn.WriteLine(SOAPRequest);
}
}
using (FileStream fsOut = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Response_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swOut = new StreamWriter(fsOut, Encoding.UTF8)) {
swOut.WriteLine(SOAPResponse);
}
}
byte[] byteSOAPResponse = UTF8Encoding.UTF8.GetBytes(SOAPResponse);
using (Stream StreamSender = Response.OutputStream) {
StreamSender.Write(byteSOAPResponse, 0, byteSOAPResponse.Length);
StreamSender.Close();
}
Response.Close();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ProcessRequest_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine("TryCatch : ");
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
}
Do you have any suggestions?
|
|
|
|
|
Sometimes one try-catch is sufficient.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry Schmitz,
I know this, but I might to throw again the exception. This is more simple to debug like this. Each catched exception is specific. I know exactly within the specific method where it crashes. I am sorry! If we find the problem, I will make another code with just one try-catch and I will post to you.
Other than that, do you know where I made a mistake? I recall to you that this code runs perfectly within Windows Forms Application.
Have a nice day my friend!
|
|
|
|
|
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
1) What WaitForPendingFinalizers does ?
it suspend the current thread and clear the memory?
2) Why GC.Collect(); called twice when we use GC.WaitForPendingFinalizers(); ?
3) GC.WaitForPendingFinalizers(); slow down the performance of the application....why ?
Thanks
|
|
|
|
|
|
I am trying to find data in xml file using LINQ but my ANY() or WHERE clause found no data. what is the problem in my approach not clear.
I have a xml file which which has been created by Dataset WriteXml() function. that file i am querying by LINQ and data not found occur.
See my XML structure
<?xml version="1.0" standalone="yes"?>
<TER_ViewAll>
<dgvViewAll_Vertical>
<Section_x0020_>ML</Section_x0020_>
<LineItem>BofA Merrill Lynch</LineItem>
<Revise_x0020_Date>01-16-2018</Revise_x0020_Date>
<_x0032_010_x0020_FYA>1608.6500</_x0032_010_x0020_FYA>
<_x0032_011_x0020_FYA>1429.0610</_x0032_011_x0020_FYA>
<_x0032_012_x0020_FYA>1656.7500</_x0032_012_x0020_FYA>
<_x0032_013_x0020_FYA>1427.9330</_x0032_013_x0020_FYA>
<_x0031_Q_x0020_2014A>321.0100</_x0031_Q_x0020_2014A>
<_x0032_Q_x0020_2014A>525.5670</_x0032_Q_x0020_2014A>
<_x0033_Q_x0020_2014A>478.0100</_x0033_Q_x0020_2014A>
<_x0034_Q_x0020_2014A>323.2360</_x0034_Q_x0020_2014A>
<_x0032_014_x0020_FYA>1647.8230</_x0032_014_x0020_FYA>
<_x0031_Q_x0020_2015A>342.4010</_x0031_Q_x0020_2015A>
<_x0032_Q_x0020_2015A>512.7390</_x0032_Q_x0020_2015A>
<_x0033_Q_x0020_2015A>465.9940</_x0033_Q_x0020_2015A>
<_x0034_Q_x0020_2015A>318.4440</_x0034_Q_x0020_2015A>
<_x0032_015_x0020_FYA>1639.5780</_x0032_015_x0020_FYA>
<_x0031_Q_x0020_2016A>430.9940</_x0031_Q_x0020_2016A>
<_x0032_Q_x0020_2016A>531.7920</_x0032_Q_x0020_2016A>
<_x0033_Q_x0020_2016A>410.4750</_x0033_Q_x0020_2016A>
<_x0034_Q_x0020_2016A>379.9890</_x0034_Q_x0020_2016A>
<_x0032_016_x0020_FYA>1753.2500</_x0032_016_x0020_FYA>
<_x0031_Q_x0020_2017A>456.9130</_x0031_Q_x0020_2017A>
<_x0032_Q_x0020_2017A>696.9010</_x0032_Q_x0020_2017A>
<_x0033_Q_x0020_2017A>503.3780</_x0033_Q_x0020_2017A>
<_x0034_Q_x0020_2017A />
<_x0032_017_x0020_FYA />
<_x0031_Q_x0020_2018A />
<_x0032_Q_x0020_2018A />
<_x0033_Q_x0020_2018A />
<_x0034_Q_x0020_2018A />
<_x0032_018_x0020_FYA />
<_x0031_Q_x0020_2019A />
<_x0032_Q_x0020_2019A />
<_x0033_Q_x0020_2019A />
<_x0034_Q_x0020_2019A />
<_x0032_019_x0020_FYA />
<_x0031_Q_x0020_2020A />
<_x0032_Q_x0020_2020A />
<_x0033_Q_x0020_2020A />
<_x0034_Q_x0020_2020A />
<_x0032_020_x0020_FYA />
<_x0031_Q_x0020_2021E />
<_x0032_Q_x0020_2021E />
<_x0033_Q_x0020_2021E />
<_x0034_Q_x0020_2021E />
<_x0032_021_x0020_FYE />
<_x0031_Q_x0020_2022E />
<_x0032_Q_x0020_2022E />
<_x0033_Q_x0020_2022E />
<_x0034_Q_x0020_2022E />
<_x0032_022_x0020_FYE />
<GroupKey>Consensus Model~Net Revenue~TRIN~NBM~~1~ML</GroupKey>
</dgvViewAll_Vertical>
</TER_ViewAll>
the above xml is one records and xml file has many records like above one. i load that xml file by data ser and querying by LINQ. this way i am querying.
private void button1_Click(object sender, EventArgs e)
{
string QCViewPath_savepath = @"C:\RDSS WorkBench_Stage\Data\TER\TER_QC-ViewwAll.xml";
DataSet ds = new DataSet();
ds.ReadXml(QCViewPath_savepath);
if (ds.Tables[0].AsEnumerable().Any(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Contains("Consensus Model")
&& a.Field<string>("GroupKey").Contains("Net Revenue")
&& a.Field<string>("GroupKey").Contains("NBM")
&& a.Field<string>("GroupKey").Contains("1")
&& a.Field<string>("GroupKey").Contains("ML")
))
{
ds.Tables[0].AsEnumerable().Where(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Split('~')[0].Trim() == "Consensus Model"
&& a.Field<string>("GroupKey").Split('~')[1].Trim() == "Net Revenue"
&& a.Field<string>("GroupKey").Split('~')[3].Trim() == "NBM"
&& a.Field<string>("GroupKey").Split('~')[4].Trim() == "1"
&& a.Field<string>("GroupKey").Split('~')[5].Trim() == "ML"
).ToList<DataRow>()
.ForEach(r =>
{
r["2010 FYA"] = 1200;
});
}
}
My object is to update data table periodical value and save that data at last after all update. after querying data table i am getting Enumeration yielded no results
please help with rectified code. Thanks
modified 10-Apr-21 8:01am.
|
|
|
|
|
You have no field in your XML called "Section ":
if (ds.Tables[0].AsEnumerable().Any(a => a.Field<string>("Section ") == "ML"
&& ...
))
So the first test will always fail.
You have "Section_x0020_" but no "Section " ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Sir xml was created by data table writexml function data looks like & see how Section element looks in xml <section_x0020_>ZB that is why we need to add space end of Section other wise program will throw run time error.
<dgvViewAll_Vertical>
<Section_x0020_>ZB</Section_x0020_>
<LineItem>B. Riley Securities</LineItem>
<Revise_x0020_Date>02-09-2021</Revise_x0020_Date>
<_x0032_010_x0020_FYA />
<_x0032_011_x0020_FYA />
<_x0032_012_x0020_FYA />
<_x0032_013_x0020_FYA />
<_x0031_Q_x0020_2014A />
<_x0032_Q_x0020_2014A />
<_x0033_Q_x0020_2014A />
<_x0034_Q_x0020_2014A />
<_x0032_014_x0020_FYA />
<_x0031_Q_x0020_2015A />
<_x0032_Q_x0020_2015A />
<_x0033_Q_x0020_2015A />
<_x0034_Q_x0020_2015A />
<_x0032_015_x0020_FYA />
<_x0031_Q_x0020_2016A />
<_x0032_Q_x0020_2016A>3333.3865</_x0032_Q_x0020_2016A>
<_x0033_Q_x0020_2016A>3878.1150</_x0033_Q_x0020_2016A>
<_x0034_Q_x0020_2016A>4376.5020</_x0034_Q_x0020_2016A>
<_x0032_016_x0020_FYA />
<_x0031_Q_x0020_2017A>3340.3645</_x0031_Q_x0020_2017A>
<_x0032_Q_x0020_2017A>3711.3744</_x0032_Q_x0020_2017A>
<_x0033_Q_x0020_2017A>4310.8500</_x0033_Q_x0020_2017A>
<_x0034_Q_x0020_2017A>5041.2855</_x0034_Q_x0020_2017A>
<_x0032_017_x0020_FYA>16403.8744</_x0032_017_x0020_FYA>
<_x0031_Q_x0020_2018A>4867.8009</_x0031_Q_x0020_2018A>
<_x0032_Q_x0020_2018A>5167.5060</_x0032_Q_x0020_2018A>
<_x0033_Q_x0020_2018A />
<_x0034_Q_x0020_2018A />
<_x0032_018_x0020_FYA />
<_x0031_Q_x0020_2019A />
<_x0032_Q_x0020_2019A>3545.9127</_x0032_Q_x0020_2019A>
<_x0033_Q_x0020_2019A>3308.1080</_x0033_Q_x0020_2019A>
<_x0034_Q_x0020_2019A>3911.1380</_x0034_Q_x0020_2019A>
<_x0032_019_x0020_FYA />
<_x0031_Q_x0020_2020A>2798.3300</_x0031_Q_x0020_2020A>
<_x0032_Q_x0020_2020A>3054.0900</_x0032_Q_x0020_2020A>
<_x0033_Q_x0020_2020A>$3,851.0000</_x0033_Q_x0020_2020A>
<_x0034_Q_x0020_2020A>4495.1620</_x0034_Q_x0020_2020A>
<_x0032_020_x0020_FYA>14198.5820</_x0032_020_x0020_FYA>
<_x0031_Q_x0020_2021E>4187.6225</_x0031_Q_x0020_2021E>
<_x0032_Q_x0020_2021E>4701.8271</_x0032_Q_x0020_2021E>
<_x0033_Q_x0020_2021E>4902.8013</_x0033_Q_x0020_2021E>
<_x0034_Q_x0020_2021E>4929.6456</_x0034_Q_x0020_2021E>
<_x0032_021_x0020_FYE>18721.8968</_x0032_021_x0020_FYE>
<_x0031_Q_x0020_2022E>4980.5665</_x0031_Q_x0020_2022E>
<_x0032_Q_x0020_2022E>5074.0862</_x0032_Q_x0020_2022E>
<_x0033_Q_x0020_2022E>5281.4401</_x0033_Q_x0020_2022E>
<_x0034_Q_x0020_2022E>5307.0933</_x0034_Q_x0020_2022E>
<_x0032_022_x0020_FYE>20643.1862</_x0032_022_x0020_FYE>
<_x0031_Q_x0020_2023E>4201.8093</_x0031_Q_x0020_2023E>
<_x0032_Q_x0020_2023E>4211.1577</_x0032_Q_x0020_2023E>
<_x0033_Q_x0020_2023E>4220.5062</_x0033_Q_x0020_2023E>
<_x0034_Q_x0020_2023E>4220.5062</_x0034_Q_x0020_2023E>
<_x0032_023_x0020_FYE>16853.9796</_x0032_023_x0020_FYE>
<GroupKey>Consensus Model~Total Revenue~TRIN~NBM~~1~ZB</GroupKey>
</dgvViewAll_Vertical>
|
|
|
|
|
So what? You STILL don't have anything in that XML called "Section".
If this XML is being written incorrectly, I think the problem would come down to the code that generated the original datatable and/or the code that wrote it to the file.
|
|
|
|
|
The underscore character '_' is not a "special character" in XML data - it does not indicate to anything standard that the hex value between a pair of underscores should be treated as a single Unicode character. It's just a valid character in an element name, is all. So an XML element called "Section_x0020_" is not equivalent to a table column called "Section " or even "Section" - it becomes a column named "Section_x0020_" is all.
Even if it was - which it isn't - ending a field or element name with an "invisible character" would be a very poor practice!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|