Anyone know how to reference a dataSet for example if I called it dataSet5 and don't want to use it's name.
For example if I would normally use this call to display a particular tables cell value
MessageBox.Show(dataSet5.Tables[0].Rows[0][0].ToString());
How can I do the same as above using indexing so I can throw it in an incrementing loop similar to below which doesn't work. I was hoping maybe it's either part of an array of form elements or components that way I can access it something like below.
MessageBox.Show(dataSets[24].Tables[0].Rows[0][0].ToString());
Using SharpDevelop
If you want to call datasets by index you have to have an array of dataset.
DataSet[] alldatasets = new DataSet[5];
Even better if you put the datasets in a List. IE.
List<DataSet> listDatasets = new List<DataSet>();
listDatasets.Add(new DataSet());
listDatasets[0].Tables[0].Rows[0][0].ToString();
You need to put the DataSets into your own array:
private DataSet[] dataSets;
...
dataSets = new DataSet[] { ... };
Related
Consider the following data
I am trying to update the property name from givenName to PetName. Below are the things I tried.
Option 1:
List<PatchOperation> patchOperations = new List<PatchOperation>();
dynamic data = new
{
PetName= "Dummy"
};
//Remove the 0th element from the pet array
patchOperations.Add(PatchOperation.Remove("/children/0/pets/0"));
//insert the new entity
patchOperations.Add(PatchOperation.Add<dynamic>("/children/0/pets/0", data));
await Container.PatchItemAsync<dynamic>("AndersenFamily", new
PartitionKey("AndersenFamily"), patchOperations);
This works on the first element (as I have specified the index as 0).
But I couldn't find a way to update all the elements in the array. Something like /children/*/pets (I get an error "Invalid navigation for array(*)").
Option 2:
Read all the data from the database, remove the existing pets and upload the new object with the property PetName. But I guess it will take lot of time to loop through all the objects and make these changes.
Can someone suggest a better solution or a way to fix the partial updates so that it updates all the elements in the array?
The actual dataset that I am working on is huge and has more nested arrays.
Yes you are right, Current version of Patch does not support patching nested array. You need to know the index in order to replace/add values as you mentioned in the first question.
One way to think about this would be to write your own logic to replace the keys , there are libraries available in dotnet and then using the bulk insert using the SDK to insert those documents.
I'm trying to make an rdlc report in Visual Studio 2015 for a single instance of an object. It seems as though I always have to pass in an enumerable list as the datasource, and it always has a table.
Is it possible to just pass in a single object and not have a table? I want to have a background image and use text boxes to display the data that I want to display.
Thank you for any responses!
There are a couple of ways to accomplish this.
If it's just a single item, why not just use a parameter? Just pass your single value via a parameter.
If you want to go the data source route, yes, you have pass in an enumerable, but that is as easy as this:
var data = new string[] { "my value"}
and using the First function:
=First(Fields!ProductNumber.Value, "Category")
Either way, you can still use textboxes.
I am getting a strange problem.
I have a static method which is in common DLL and returns a static array of countries from the database.
And using this common method, I am trying to fill a Drop down of Country.
So code will be as below.
In Common - Helper Class DLL code
public static string[] Countries()
{
string qry = "select * from Countries";
Dataset result=SqlHelper.ExecDS(qry);
countryArray = new string[100];
//Filing country array
return countryArray;
}
In the current project
countryOptions = new string[100];
countryOptions = Common.Helper.Countries();
I know Drop Down should be bind with DS only but as his is in common DLL i cannot change this.
But now only problem I am facing is even if delete a row from Countries table it is effect is not coming in Countries array.
Common.Helper.Countries() is still returns that row. I have double checked that the row has been deleted but its effect is not coming. Can someone please help me with this??
I know Drop Down should be bind with DS only
if you mean Drop Down list can only bind with DataSet, that is not correct. See Binding DropDownList Using List Collection, Enum and DataSet in ASP.NET
if I delete a row from Countries table it is effect is not coming in
Countries array
put a break point on the following line, see if the array is getting populated.
countryOptions = Common.Helper.Countries();
Call dropDownList.DataBind(); to refresh the drop down list
How do you fill the array? I think this is where the error occurs.
Besides, your array does not need to be initialised twice:
// Creates a 100-item-array that is never actually used, so
// this line looks unnecessary
countryOptions = new string[100];
// Creates another array on the heap, leaving above array
// to GC
countryOptions = Common.Helper.Countries();
Actually the problem was since array is static i must need to restart IIS otherwise it will take the same value.
I'm working on a Silverlight project trying to access a database using LINQ To DataSet and then sending data over to Silverlight via .ASMX web service.
I've defined my DataSet using the Server Explorer tool (dragging and dropping all the different tables that I'm interested in). The DataSet is able to access the server and database with no issues.
Below is code from one of my Web Methods:
public List<ClassSpecification> getSpecifications()
{
DataSet2TableAdapters.SpecificationTableAdapter Sta = new DataSet2TableAdapters.SpecificationTableAdapter();
return (from Spec in Sta.GetData().AsEnumerable()
select new ClassSpecification()
{
Specification = Spec.Field<String>("Specification"),
SpecificationType = Spec.Field<string>("SpecificationType"),
StatusChange = Spec.Field<DateTime>("StatusChange"),
Spec = Spec.Field<int>("Spec")
}).ToList<ClassSpecification>();
}
I created a "ClassSpecification" data class which is going to contain my data and it has all the table fields as properties.
My question is, is there a quicker way of doing the assignment than what is shown here? There are actually about 10 more fields, and I would imagine that since my DataSet knows my table definition, that I would have a quicker way of doing the assignment than going field by field. I tried just "select new ClassSpecification()).ToList
Any help would be greatly appreciated.
First, I'll recommend testing out different possibilities using LINQPad, which is free and awesome.
I can't quite remember what you can do from the table adapter, but you should be able to use the DataSet to get at the data you want, e.g.
string spec = myDataSet.MyTable.Rows[0] // or FindBy... or however you are choosing a row
.Specification;
So you might be able to do
foreach(var row in myDataSet.MyTable.Rows) {
string spec = row.Specification;
...
}
Or
return (from row in myDataSet.Specification
select new ClassSpecification()
{
Specification = row.Specification,
SpecificationType = row.SpecificationType,
StatusChange = row.StatusChange,
Spec = row.Spec,
}).ToList<ClassSpecification>();
Or even
return myDataSet.Specification.Cast<ClassSpecification>()
Not sure if the last one will work, but you can see that there are several ways to get what you want. Also, in my tests the row is strongly typed, so you shouldn't need to create a new class in which to put the data - you should just be able to use the existing "SpecificationRow" class. (In fact, I believe that this is the anemic domain model anti-pattern.)
So are you using a dataset for lack of a Linq provider to the database? That is the only reason I would consider this move. For instance, with Linq to Sql you can drag the table out and drop it. Then you have instant objects with the shape you want for it.
I want to create a simple class that is similar to a datatable, but without the overhead.
So loading the object with a sqldatareader, and then return this custom datatable-like object that will give me access to the rows and columns like:
myObject[rowID]["columnname"]
How would you go about creating such an object?
I don't want any built in methods/behavior for this object except for accessing the rows and columns of the data.
Update:
I don't want a datable, I want something much leaner (plus I want to learn how to create such an object).
This type of structure can be easily created with a type signature of:
List<Dictionary<string, object>>
This will allow access as you specify and should be pretty easy to populate.
You can always create an object that inherits from List < Dictionary < string, object > > and implements a constructor that takes a SqlDataReader. This constructor should create a enw dictionary for each row, and insert a new entry into the dictionary for each column, using the column name as the key.
I think you're missing something about how .Net works. The extra overhead involved in a DataTable is not significant. Can you point to a specific performance problem in existing code that you believe is caused by a datatable? Perhaps we can help correct that in a more elegant way.
Perhaps the specific thing you're asking about is how to use the convenient ["whatever"] indexing syntax in your own table object.
If so, I suggest you refer to this MSDN page on indexers.
Dictionary<int,object[]> would be better than List<Dictionary<string, object>>. You don't really need a dictionary for each row, since column names are the same for all rows. And if you want to have it lightweight, you should use column indexes instead of names.
So if you have a column "Name" that is a 3rd column, to get its value "Name" from a row ID 10, the code would be:
object val = table[10][2];
Another option is SortedList<int,object[]>... depending on the way you access the data (forward only or random access).
You could also use MultiDictionary<int,object> from PowerCollections.
From the memory usage perspective, I think the best option would be to use a single dimension array with some slack capacity. So after each, say 100, rows, you would create a new array, copy the old contents to it and leave 100 empty rows at the end. But you would have to keep some sort of an index when you delete a row, so that it is marked as deleted without resizing the array.
Isn't this a DataSet/DataTable? Maybe I didn't get the question.
Also, what is the programming language?