how can search data on multiple field on mongoDB with C#? - c#

I am using MongoDB with C# Driver
I try to fetch data based on search as an like from collection using following code:
col.Find(new BsonDocument(new BsonElement("Name", new BsonRegularExpression(search)))).ToList();
it's work for single field data search but how can do with this multiple field.

Related

Grabbing Certain Parts of XML Stored in DB - ASP.NET

In my database I have a column that stores XML data, the database items are accessed through my model. However I need to be able to access specific items within the XML column, and convert them into a string to be used on my web page, what's the best way of doing this?
Example:
<DATAROW AgreementNumber="0000000" LoanAmount="£0.00" LoanTerm="20"
Title="Miss" FirstName="Joe" LastName="Bloggs"/>

MongoDB C# Driver, httprequest.json to BSON, then insertMany

I want to replace a stock price data AccessDB with a MongoDB using MongoDB c# driver.
The download data using xmlhttprequest as json string is shown below (2 dates only):
[{"date":"2016-01-04T00:00:00.000Z","close":2.77,"high":2.82,"low":2.63,"open":2.77,"volume":32516771},{"date":"2016-01-05T00:00:00.000Z","close":2.75,"high":2.8,"low":2.64,"open":2.77,"volume":12972260},....]
I have studied the c# driver documentation and conducted web searches, but can't find anything that I can get to work. I could parse the each document (i.e, price for a symbol and a date) in the json string and insertOne as in the BsonDocument snippet below.
I would think that json or BSON methods exist that make to appropriate conversions to accomplish a BSON insertMany() DB load.
Please help me get up the curve by finding appropriate info and learn how to do this.
Thank you.
The below works with manual conversion from above JSON data for 1 date
BsonDocument stkDoc = new BsonDocument
{
{"symbol","AMD"},
{"date","2016-01-04T00:00:00.000Z"},
{"close",2.77},
{"high",2.82},
{"low",2.63},
{"open",2.77},
{"volume",32516771}
};
_client = new MongoClient();
_db = _client.GetDatabase("stkprices");
var collection = _db.GetCollection("stkdata1");
collection.InsertOne(stkDoc);

Fill existing SQLite database with data from JSON (or other easily-readable text format) in C#

My database is divided into two parts: language-independent part and localizable part (containing Unicode text strings). For our translation staff it's much more easier to work not with some DB viewing tool but with some text format like JSON (via some tool of course). So I'm looking for a best way to load JSON data into my SQLite database. For now I use the foolowing approach (assume that I already have empty SQLite database):
I deserealise JSON data into C# classes (via Newtonsoft.JSON.dll).
For each of them I manually create INSERT command with paremeters (via System.Data.SQLite.dll) and then fill that parameters with class fields' values
I execute that command.
Is that correct (easiest, reliable) aproach to fill SQLite database with JSON data? Maybe I've missed some useful API?
Any other easily-readable text format (with Unicode support!) which is better to work with in term of C# and SQLite is welcomed.
Try Sqlite.NET, a basic Sqlite client and ORM: https://github.com/praeclarum/sqlite-net
From their wiki:
Once you have defined your entity, you can automatically generate
tables in your database by calling CreateTable:
var db = new SQLiteConnection("foofoo");
db.CreateTable<Stock>();
db.CreateTable<Valuation>();
You can insert rows in the database using Insert. If the table
contains an auto-incremented primary key, then the value for that key
will be available to you after the insert:
public static void AddStock(SQLiteConnection db, string symbol) {
var s = db.Insert(new Stock() {
Symbol = symbol
});
Console.WriteLine("{0} == {1}", s.Symbol, s.Id);
}
Similar methods exist for Update and Delete.
You would get something like this:
AddStock(string jsonString){
var stock = JsonConvert.DeserializeObject<Stock>(jsonString);
db.Insert(stock);
}

Create lines in the Axapta journal

I do WCF-srvice on C# which must get data from Axapta's tables. I can create new AxaptaRecord, and create new record in table.
using (axRecord = axapta.CreateAxaptaRecord(tableName)) //this create new record
{
axRecord.set_Field("name", "firstname");
-//-
axRecord.Insert();
}
This code show, how I get data from this tables.
using (axRecord = axapta.CreateAxaptaRecord(tableName))
{
axRecord.ExecuteStmt("select * from %1");
while (axRecord.Found)
{
ToroEquipment temp=new ToroEquipment();
temp.num_journal=axRecord.get_Field("text").ToString();
lToroEq.Add(temp);
axRecord.Next();
}
}
Also, all tables can have linked table, which contain lines with other data.
I can read data from this lines. I use the above code with the modified query (I add condition with "where").
So, how can I insert data from this lines in C#?
Can you give me some examples of code for this?
It seems you are using the .NET Business Connector, not AIF.
So you can find an example to insert data using the .NET BC here: https://msdn.microsoft.com/en-us/library/aa868997.aspx
If you want to use WCF, you can activate the LedgerServices service group and add the LedgerGeneralJournalService document datasource and use it directly as WCF service.

Reading / writing to entity field using name stored in variable

I have a winforms application which uses Linq to SQL. One of my database tables has a number of fields like this...
Area_1
Area_2
Area_3...
I need to be able to access these fields dynamically at runtime. I have a number of wired up buttons on my form which correspond to the different areas, so I created a string like this...
String sField = String.Format("Area_{0}", myAreaNumber);
And need to be able to read / write to the specific field using this variable. At this stage, I have already grabbed the entity object I need to work with. How can I go about using the 'sField' variable to read / write to a field?
You can run raw SQL directly on database using SqlQuery method on DbSet:
context.YourDbSet.SqlQuery("query string")

Categories

Resources