Cant use DataTable.New - c#

Im trying to read a csv file using CSVTools library the code that I have to use to get the csv file in to a data table is,
var dt = DataTable.New.ReadLazy(filename);
But the problem is there is no ".New" keyword. When I write DataTable.New it shows an error. Can someone help me ?

You need to include using statement on top of c# file as below
using DataAccess;
or use
var dt = DataAccess.DataTable.New.ReadLazy(filename);

Which means the DataTable that you are using is not belongs to the
expected namespace, use fully qualified name to get the correct
class.
You may have both using DataAccess; as well as System.Data in your using section, so by declaring DataTable alone will made compiler to assumes that it belongs to System.Data. By specifying the DataTable as DataAccess.DataTable you can help the compiler to find the exact class that you are looking for. This kind of specification is called fully qualified names. Make use of them and come out from that specified error. Your declaration will be like the following:
var dt = DataAccess.DataTable.New.ReadLazy(filename);

Related

Why use the following statement using aName = library in c#?

I was searching a ZigBee library for c# and I found GBee. I took a look to the code and I've found the following statement:
using AtCmd = NETMF.OpenSource.XBee.Api.Common.AtCmd;
Why is used this statement and what means?
Searching into the code I also found that AtCmd is used as a "class" to send standard command e.g.(AtCmd.RestoreDefaults,AtCmd.NetworkReset)
This meas, that all AtCmd statements in code will become from NETMF.OpenSource.XBee.Api.Common namespace. It simply means 'default namespace' for this type.
Probably you have in code two exact names, but deriving from different namespaces.
From MSDN:
This is called a using alias directive

System.Xml.Linq could not be referenced properly at WEALTHLAB editor

I am trying to write C# code that does basically the following:
The code connects to MySql table and reads data from one MySql table (with r rows and c columns) - no issues here, everything when fine;
The code then defines and loads one DataTable with the help MySqlDataReader - again, no issues at this stage. Code is fine;
Each column of this datatable is in fact one strategy parameter of the strategy (i.e. each row of this datatable thus becomes one parameter set of the strategy.
Having said that:
the code then loops across all of the rows of this datatable;
the code gets the column values of each row one by one, and changes the XML elements one by one to replace old strategy values with the new ones - THIS IS WHERE I GET THE ERROR!!! I CANT MODIFY THE XML FILE FROM WITHIN WEALTHLAB C# EDITOR!!
that way, the strategy becomes configured with a new set of parameters each time;
the code then calls runDonor and runs the strategy with given (new) set of parameters - no problem at calling runDonor as well!;
and finally, certain statistics are recorded and inserted into one MySql table - there is no problem here as well;
**
Considering that a large chunk of this code is not related to wealthlab namespace, I coded most of the parts in Visual Studio first, compiled there using Visual Studio compiler, and seen that the code works just fine there! (i.e.the Xelement edits went just fine. I could see that the XML file is being modified after each loop when this code is run at Visual Studio!)
Then, I copied/pasted this code onto wealthscript editor, but unfortunately, the code did not compile!!.
**
The problem is at the region where I begin modifying the XML document, using ElementAt method.
More specifically, the ElementAt statement works fine at Visual Studio Editor, whereas it doesnt at Wealthlab editor.
To repeat, DESPITE THE FACT THAT I GIVE REFERENCE TO SAME DLLS AND USE THE SAME USING... STATEMENTS ON TOP OF THE CODE, Visual Studio returns no errors and runs thoroughly whereas Wealthlab returns this error:
'System.Collections.Generic.IEnumerable' <System.Xml.Linq> does not contain a definition for 'ElementAt'
and no extension method 'ElementAt' accepting a first argument of type
'System.Collections.Generic.IEnumerable' <System.Xml.Linq> could be found (are you
missing a using directive or an assembly reference?)"
I have been googling for ages, and could not come up with any decent solution yet.
And since I dont have a programming background, I really cant figure out why the same code, that uses the same references, and the same using directives, works at Visual Studio but yield errors at Wealthlab.
At this link, one solution alternative is vowed, but frankly, it is not english to me:
System.Xml.Linq.XElement>' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of
**
So, my question would be two fold:
1- How can I overcome this interesting error that is related to proper refererencing to System.Xml.Linq? Obviously, this is where the problem lies.
2- Or, lets throw this out and start from the scratch: How do you guys modify your xmls? It would be splendid If I was provided a link of example codes that reads from xml files, or modifies them, saves them.
(Please, help...)
For you guys to repeat the same error I also attach here the whole of the code; copy this to your editors and see if the code runs ok:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components;
using System.Collections;
using System.Xml;
using System.Xml.XPath;
using System.Linq;
using System.IO;
using System.Data;
using System.Xml.Linq; // THIS IS WHERE THE PROBLEM IS THIS REFERENCE COULD NOT BE SET PROPERLY!! WHY?!!
using MySql.Data.MySqlClient;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
// public DateTime now;
public static XElement SourceXml;
public static XElement DonorStrategyXml;
public static string SourceXmlName;
public static string Ticker;
public static int nNames;
public string DonorStrategyXmlFolder;
public string DonorStrategyXmlName;
public string DonorStrategyXmlNameWithNoXml;
public string DonorStrategyXmlPathName;
protected override void Execute()
{
//....
//....
//....
DonorStrategyXmlFolder = #"C:\Users\Aykut\AppData\Roaming\Fidelity Investments\WealthLabDev\1.0.0.0\Data\Strategies\Customized\";
DonorStrategyXmlName = "sss.xml";
DonorStrategyXmlNameWithNoXml = "sss";
string DonorStrategyXmlPathName = DonorStrategyXmlFolder + DonorStrategyXmlName;
DonorStrategyXml = XElement.Load(DonorStrategyXmlPathName);
foreach (DataRow dbBandParameterRow in dbBandParameters.Rows) {
foreach (DataRow dbNNParameterRow in dbNNParameters.Rows) {
string ResultID = dbBandParameterRow["ResultID"].ToString();
int nE = 0;
//....
//....
//.THIS IS WHERE THE PROBLEM LIES AT!!...
DonorStrategyXml.Elements("ParameterValues").Descendants("double").ElementAt(nE).Value = dbBandParameterRow["RatioForUpper"].ToString();
nE++;
DonorStrategyXml.Elements("ParameterValues").Descendants("double").ElementAt(nE).Value = dbBandParameterRow["ADXPeriodForUpper"].ToString();
// output certain statistics of the strategy onto mysql // later!!!
//....
//....
PrintDebug("NetProfit:" + sp.Results.NetProfit.ToString());
}
}
}
} // class
} // nspace
The wealthlab support team returned with the following answer; and it worked.
Thanks.
...
the code won't compile in the current version 6.6 of Wealth-Lab's Editor.
To fix that, add references to System.Core.dll and System.Xml.Linq.dll from c:\windows\microsoft.net\framework64\v4.0.30319 (64-bit WLD, or c:\windows\microsoft.net\framework\v4.0.30319 for 32-bit WLD).
...

C# CopyToDataTable method not working

I have been searching on how to fix this for many hours now and I cant seem to quite figure it out. What I am trying to do is select a portion of 1 table and copy it to a temp table (my application needs to work with specific groups at a time). When I try to implement the CopyToDataTable() method i get an error saying:
Parameter count mismatch
and it highlights line 137 in the ObjectSchredder.cs file (the one from microsofts website). My code is below:
private void fillTempTable()
{
IEnumerable<DataRow> tempResults = from row in sourceTable.AsEnumerable()
where row.Field<String>("GroupID") == GetCurrentGroupName()
select row;
tempGroup = tempResults.CopyToDataTable<DataRow>(); //Everything seems to work until this line
}
You don't need the CopyToDatatable method which works with any types(even with anonymous types) that Microsoft provides with the ObjectShredder class. You are selecting DataRows from a DataTable, hence the normal CopyToDataTable works without a problem. It is sitting in the DataTableExtensions class in the System.Data.DataSetExtensions.dll.
So i assume this is just a namespace issue. Remove the using from the dynamic CopyToDataTable extension method and try this:
tempGroup = tempResults.CopyToDataTable();
If that doesn't help rename the custom CopyToDataTable<T> method.

Why dataTable Name is necessary to be given in webServices

I wondering why it throws a error whenever i not intended to give name of datable.As we know there are constructor for datable class is overloaded.so If i using parameter less constructor is give the error by the basis of serialization .
Can Someone Explain Me why to use Parametrized one but not default for DataTable .
It's because the name is required for the data table to serialize properly.
Why is this? Well, the exact reason seems to be that the serialization process uses the table name as a key, and specifically, an empty data set is created to import it back in. When the name is not present, the part that looks for the table name throws an exception and this is why you see the error you are getting.
You don't have to use the constructor, though, you can set the TableName outside:
DataTable myTable = new DataTable();
myTable.TableName = "PleaseDontKillMySerialization";
If you are interested, you can look at the contents of the class using ILSpy. This way you can see for yourself how the class is created and look at how serialization works for this class.
As Marc mentions, though, using DataTable restricts you to .Net clients only. It's also quite a large object when serialized so more data has to be transferred per request.

"undefined function call" when using function in a DataSet

I have a DataSet in UserAdmin.xsd with many DataTables. Most of the data come directly from stored procedures. However for one of the tables, I would like to add another column which uses a C# function defined in another file.
I put for the expression for that column: Helper.ObtainUserInfo(user_nm, "displayname"); but that gives me an error "undefined function call".
Helper.cs is located under App_Code/Common/ and the namespace is COM.A.B.C. UserAdmin.xsd is located under App_Code/.
How can I access the function ObtainUserInfo()? Is there something like a using keyword that I could use?
You cannot use DataColumn.Expression to call a .NET-Method to obtain a value. You must refer a column in this table or one of the parent/child tables to calculate the value. For more informations on what you can('t) do with Expressions look here: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression%28v=VS.100%29.aspx
Instead of using a method or an expression, i would recommend to do this with SQL whenever possible.
if You provide your code, then it would be very helpful to solve your problem, anyway assuming your problem i have solution, i hope it may helped you
You can open the Code File Which Contain ObtainUserInfo() Function, then You can Refer that Class Name, in other File.
For eg : If you hav solution Named WebApplication1, inside that if you have users class, in that users class, ObtainUserinfo() function is defined,
then You Have to Use statement like this,
Using WebApplication1.Users

Categories