Harry Potter and the Sorcerer's Stone


MongoDB ma'lumotlar bazasidan ma'lumotlarni ma'lumotlar oqimi yordamida o'qiydi va uni formatlangan ko'rinishda ko'rsatadigan C# dasturini amalga oshiring


Download 192.49 Kb.
bet30/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   26   27   28   29   30   31   32   33   ...   62
Bog'liq
Algaritim amaliy-2

63. MongoDB ma'lumotlar bazasidan ma'lumotlarni ma'lumotlar oqimi yordamida o'qiydi va uni formatlangan ko'rinishda ko'rsatadigan C# dasturini amalga oshiring.
Javob:
using System;
using MongoDB.Driver;
class Program
{
static void Main(string[] args)
{
var client = new MongoClient("mongodb://localhost:27017"); // MongoDB serverga ulanish
var database = client.GetDatabase("mydb"); // Ma'lumotlar bazasi nomi
var collection = database.GetCollection("mycollection"); // Ma'lumotlar to'plami nomi

var documents = collection.Find(new BsonDocument()).ToList(); // Barcha ma'lumotlarni olish

foreach (var document in documents)
{
Console.WriteLine(document);
}
}
}
64. Ma'lumotlar oqimidan foydalangan holda shifrlangan SQLite ma'lumotlar bazasiga ma'lumotlarni o'qiydigan va yozadigan C# dasturini yozing.
Javob:
using System;
using System.Data.SQLite;
namespace SQLiteDemo
{
class Program
{
static void Main(string[] args)
{
// SQLite ma'lumotlar bazasiga ulanish uchun Connection obyektini yaratamiz
SQLiteConnection sqlite_conn;
sqlite_conn = CreateConnection();

// Ma'lumotlar bazasiga ma'lumotlarni yozish
InsertData(sqlite_conn);

// Ma'lumotlar bazasidan ma'lumotlarni o'qish
ReadData(sqlite_conn);

// Ma'lumotlar bazasidan chiqish
sqlite_conn.Close();
}

static SQLiteConnection CreateConnection()
{
// Ma'lumotlar bazasiga ulanish uchun Connection obyektini yaratamiz
SQLiteConnection sqlite_conn;
sqlite_conn = new SQLiteConnection("Data Source=sample.db;Version=3;New=False;Compress=True;");
try
{


Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   62




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling