Hello I have an object which has value "B11" i.e
object data = "B11";
i have a variable called string resultCell. How do I get B11 into resultCell.
it doesn't seem to work for me in c#. I have tried things like ....
resultCell = (string)data;
resultCell = Convert.ToString(data);
More information
I am using excel services to get a value in a cell. the excel services returns a object[]. Its a single element though. I want the value in a string. i.e. B11 in the object as string.
Much of the time, calling data.ToString() will work. Without the specific type of the data object, there isn't any way to answer the question.
Is the value stored in a property of data?
Edit: Could you try (string)object[i], where i is the index of the particular piece of data you want to retrieve? If you need every value in the array, you'll probably want to use a foreach loop.
i think you need to just assign value as data.ToString() to cell.
hope this work for you.
Related
I have an array field in my collection which have value with properties or empty value as "[]"
For fetching the documents having empty "[]" value in mongodb i use
db.getCollection('collection').find({"ArrayFieldName":{$eq:[]}})
This gives me result as expected. But when i try to form this query in the C# using mongodb driver i couldnt get the expected Result.
I tried,
filterBuilder.Eq("ArraryFieldName", "[]") and filterBuilder.Eq("ArraryFieldName", new ArraryClassName(){})
Need help with C# filter builder to specify $eq:[] for arrary field.
An instance of ArraryClassName clearly won't work because it's not an array instance - it's a single object. Likewise "[]" won't work because it's a string.
You can check directly translate your CLI query to this filter:
Builders<BsonDocument>.Filter.Eq<BsonArray>("ArraryFieldName", new BsonArray())
Though if you simply want to check that the existing array is empty, you can use this filter instead:
Builders<BsonDocument>.Filter.Size("ArraryFieldName", 0)
P.S. I would strongly suggest using C# data models as it makes everything much easier to work with.
Also, you have called your field ArraryFieldName (notice the extra r at the end of Array). If you don't have existing data with this misspelled property name, you might want to correct the spelling.
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 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
How to insert a Combobox value in to a database. When i hit Save button in my application, it will stored stored into database like this way..
System.Windows.Controls.ComboBoxItem
What i do for getting correct value of a combo box?
if you are using a string in the combobox, then you can use the example that Akash Kava showed.
Also, if the combobox contains other elements, you can get those elements through the use of something like
((ComboBoxItem)rpcombo.SelectedItem).Content.ToString()
and casting it to what you need.
lets say your combobox has string items what you need is like this
froeach( ComboBoxItem item in ComboBox1.Items )
{
string str = (str)item;
// saving value
}
Best Regards,
Iordan
This question seems a bit too broad. We are going to need nore information about this to be able to answer this one.
What kind of database are you using?
Are you connected to the database or do you need help with tahat as well?
In that case there are alot of good reading on the internet to your aid, that I can link to.
Do you want to save the ComboBoxItem as an .net object or det values of the item?
The list can go on, you have to give me something more to chew on.
MyObject obj = myComboBox.SelectedItem as MyObject;
obj.ValueIamInterestedIn; <--- this should be inserted
or if you have string or any valuetype array as ItemsSource then,
myComboBox.SelectedItem.ToString();
I'm writing a front end to a database, presenting options as comboboxes. And I need to be able to return nulls to the database.
I have a solution at the moment which involves 'fudging' a record into the query to populate the Datatable, then detecting the selection and hard coding null into my update statement if this item has been selected.
--GetDataByAvailableTechs query
SELECT tblLEMSCredentialsId, TechNumber
FROM tblLEMSCredentials AS aLEMSCreds
UNION ALL
SELECT '99999' AS Expr1, '<NONE>' AS Expr2
.
//populate combo box
BV_LEMSHIPDataSet.tblLEMSCredentialsDataTable dtAvailableTechs = taLEMSCreds.GetDataByAvailableTechs(selectedSerial);
cboTechNumber.DataSource = dtAvailableTechs;
.
//Save back to DB
if (lemsCredsID == 99999)
{
taDevice.UpdateQuery_Restage(null, selectedSerial);
}
else
{
taDevice.UpdateQuery_Restage(lemsCredsID, selectedSerial);
}
Can anyone suggest a better way of doing this please? I need to make the application cope with another 5 similar fields and don't want to create a multitude of if else versions of my update.
G
In the past I've used a similar approach but used minus numbers for the NULL values - that way you can you treat anything less than zero as NULL in one if statement.
This assumes that your ID's in the table are always positive though :)
Null object pattern. Make it return an empty string for the UI and provide a method call to extract the value when updating the database. In normal cases this will return your true value but the null object will override this behaviour to give you your null.
No magic numbers required and all you need to do is add this value to the start of the "bindable values" when you bind your control to the datasource.
You may put an string value as the combobox 'null value', for example: "thenullvalue" then parse combobox value to nullable int type (int?). For proper selection you will get the desired value, for 'null selection' you will get null (parsing "thenullvalue" to int will give you null) :)
Then save the value to database just as:
int? lemsCredsID = parseInt(combobox.Value);
//Save back to DB
taDevice.UpdateQuery_Restage(lemsCredsID, selectedSerial);
Depending of your db provider you might also need to convert nullable type null value to DBNull, like this:
taDevice.UpdateQuery_Restage((lemsCredsID==null ? DBNull : (int)lemsCredsID), selectedSerial);
Hope this helps.
If the value is intended to be null, pass null to the database would be a good solution, this reduces the extra logic handling for special values for nulls and it can be quite risky and ambiguous.
The view or application layer should be able to handle null either returned from database or passing into it.
e.g. you can convert null to string.Empty before binding the control as well as you can convert string.Empty to null before passing into the database.