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.
Related
I have a problem generating a table view from array json data that I have get.
I have completed of getting and saving the json data in array form, but the problem I facing is that I cannot load them into my table.
Below is my code,
client.ExecuteAsync(request, response =>
{
string json = response.Content;
Console.WriteLine(json);
List<PostInfo> curTest = JsonConvert.DeserializeObject<List<PostInfo>>(json);
for (int i = 0; i < curTest.Count; i++)
{
PostInfo t1 = curTest[i];
arraydata.Add(t1.title.rendered);
}
array1 = arraydata.ToArray();
});
UITableView _table;
_table = new UITableView
{
Frame = new CoreGraphics.CGRect(0, 20, View.Bounds.Width, View.Bounds.Height - 20),
Source = new TableSource(array1)
};
View.AddSubview(_table);
The table returns a blank page when I trying to put the array1 as my TableSource. And I believe that if the array1 has nothing in the array once it out from the client.ExecuteAsync.
Can someone guide me how to generate TableView based on array get from the json data?
Your problem here is that when you try assign data source to your table view the array is still empty. Short term solution would be - re-assign datasource in async operation closure and dont forget to call TableView.ReloadData(). But it's not the prettiest solution. I would suggest you MVVMCross - You write your Core project with business logic and then you create platform project and use bindings to bind say Datasource to a collection of items. You can find tutorials with source code on the internet. There are plenty of them.
Your view doesn't realise that the source has changed. Big chance that if you get it working and change the properties of objects in your array, your view also won't know its data has changed.
Take a look at this:
https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx
Basically what this interface does is tell the view or binding that something has changed. This way the view knows not only to update, if you are smart about it it only updates 1 value, the one that changed.
Now for your current problem, how to fix it with this interface? Simply change your array to an ObservableCollection -> https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx
An ObservableCollection is like a List but it already has the INotifyPropertyChanged interface implemented.
I am having to call a ColdFusion web service which returns a QueryBean. Which returns a set of complex arrays that have the values I am looking for. When I make the call I get all the data in the arrays that I am expecting but now I am trying to get to the data and it keeps telling me that I am missing something or I can't use indexing with an object.
I created a web reference called DAM_Search in VS2010 and I call it with this command;
DAM_Folder.folderService obj_Folder = new DAM_Folder.folderService();
DAM_Folder.QueryBean qBean = bj_Folder.getfolder("1-Key", str_Folder_ID);
What I get back is qBean which contains 4 arrays in it, with the first two arrays are
qBean.columnList[10]
qBean.columnListField[10]
and contain the names of the fields that are used in the data rows. Next it has
qBean.data[4]
qBean.dataField[4]
This is where the data is returned. In the example above the qBean in returning 4 rows of data. The data is in an array with the values of the columns named in the columnList[10].
I figure that since a picture is worth a 1000 words, this might help.
(source: sapp-family.com)
What I am trying to do now is get the data from the internal array of qBean.data[0][0]. In the Immediate Window when I try ? qBean.data[0] it returns the correct array of values.
I have tried the following
? qBean.data[0][0]
"Cannot apply indexing with [] to an expression of type 'object'"
? qBean.data[0].[0]
Identifier expected
? qBean.data[0,0]
Wrong number of indices inside []; expected 1
So, my fellow Stackoverflow users, what do I need to do for getting the values of this object? I figure it's something simple and I am just over thinking it, but it is just driving me up a wall right now.
I would try qBean.data[0][0].toSting()
Ok, So I got side tracked and did not go back and update the original question with a work around. Sorry about that...
My solution to the issue is to cast the qBean.Data[0] as an IEnumerable object. I then run it through a foreach loop which feeds the data into an array that I can pass back to the calling function. For example;
string[] FileData = new string[0];
foreach (var var_Value in (IEnumerable)qBean.data[0])
{
Array.Resize<string>(ref FileData, FileData.Length + 1);
FileData[FileData.Length-1] = var_Value.ToString();
}
Now that I know this works, I am going to pull a count from the other array in the QueryBean and set the FileData[] size before I start the foreach so I don't have to copy the array 21 times with the Array.Resize<>. While at the moment the data I am working with is small, I never know what it's going to be in the future.
Tim
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[] { ... };
----> I have datatable which is passing to another page in session variable.
----> Now on another page i take the session variable into datatable.
datatable ds_table = new datatable();
ds_table = (datatable)session["table_value"];
----> so problem, is that , when i filtering some rows from ds_table . that taking effect in the session variable. if some rows deleted from ds_table. then it is also deleted from session variable.
----> so, anyone tell me why is this going to happene?
help me. its necessary.
I would suggest that you copy the datatable before placing it in session. Then, it won't be affected by any changes you make later to the original datatable.
All you have to do is declare a new DataTable variable and copy it:
private void CopyDataTable(DataTable table){
// Create an object variable for the copy.
DataTable copyDataTable;
copyDataTable = table.Copy();
// Insert code to work with the copy.
}
Then you can put copyDataTable into session.
Well, if session["table_value"] points to the datatable, and you make assign its value (the datatable) to another variable, and THEN MAKE CHANGES to that variable, the changes will be relfected in the datatable and thus you'll see the effect you illustrated.
----- Not always, but in the case you illustrated (so is datatable a shared resource?)
Sounds like you want to make a copy of the DataTable. Try this:
ds_table = ((datatable)session["table_value"]).Copy();
This will be bad if the DataTable is large, so bear that in mind. That said using Session for a large DataTable sounds like a bad idea anyway!
Of course whether that works or not depends on where you are changing its state (I've made some big assumptions). Perhaps describe in more detail what you are doing, and you will get more help (e.g. a code example).
I create a custom dataset that I pass off to a black boxed component. The dataset consists of usually 5-6 tables (with unique names assigned by me). The component takes the dataset and builds a drop down combo box based off the table names. What I am needing to do though is to change the ordering of the tables within the dataset. I need to do this so I first offer up to the user the appropriate selection in the drop down (based off what section in the application they are in). So for instance...if they are in "Section A" then that is the first table name shown in the drop down list...if the user goes to "Section F" then that is what is shown in the list first...so on and so forth.
The more code intensive way is of course to just change the ordering in which I add the tables to the dataset. This would work, but I thought there had to be some way to do this more elegantly and with less code.
I am working in C# with the 3.5 framework.
Remember that DataSets and their contents are stored on the heap, so you can have a DataTable object in more than one place in the DataSet.
Simply create your DataSet with a dummy DataTable in position zero. Then, based on whatever section they'e in, you put the corresponding table in position zero. Your table name will appear twice in your DropDownBox, once as the 'default' and again below in its proper context and order with the other tables.
public class ThisThing
{
private DataSet myDS = new DataSet();
//Populate your DataSet as normal
public DataSet ChangeLocation(int CurrentSectionNumber)
{
myDS.Table[0] = myDS.Table[CurrentSectionNumber]
}
}
I'm not sure trying to force your ordering information into the DataSet's data structure is the most intuitive approach. You might consider passing an ordered list of DataTable instead of (or in addition to) the DataSet.