```html C# SDK - CRUD Operations Examples

C# SDK - CRUD Operations Examples

Explore example code snippets demonstrating basic CRUD (Create, Read, Update, Delete) operations using the C# SDK.

Create - Adding a New Record

This example demonstrates how to create a new record in your database using the SDK.

C# Code Example

                ```csharp
                using SDKNamespace; // Replace with your SDK namespace
                using System;

                public class Example
                {
                    public static void Main(string[] args)
                    {
                        // Initialize SDK instance
                        var sdk = new SDKClient("your_api_key", "your_database_url");

                        // Create a new record
                        var newRecord = new MyObject
                        {
                            Name = "Test Record",
                            Value = 123
                        };

                        try
                        {
                            var createdRecord = sdk.CreateRecord(newRecord);
                            Console.WriteLine($"Record created with ID: {createdRecord.Id}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Error creating record: {ex.Message}");
                        }
                    }
                }
                ```
                

Read - Retrieving Records

This example shows how to retrieve existing records from the database.

C# Code Example

                ```csharp
                using SDKNamespace;
                using System;
                using System.Collections.Generic;

                public class Example
                {
                    public static void Main(string[] args)
                    {
                        // Initialize SDK instance
                        var sdk = new SDKClient("your_api_key", "your_database_url");

                        // Retrieve all records
                        try
                        {
                            List records = sdk.GetAllRecords();

                            Console.WriteLine("Records:");
                            foreach (var record in records)
                            {
                                Console.WriteLine($"  ID: {record.Id}, Name: {record.Name}, Value: {record.Value}");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Error retrieving records: {ex.Message}");
                        }
                    }
                }
                ```
                

Update - Modifying a Record

This example demonstrates updating an existing record in the database.

C# Code Example

                ```csharp
                using SDKNamespace;
                using System;

                public class Example
                {
                    public static void Main(string[] args)
                    {
                        // Initialize SDK instance
                        var sdk = new SDKClient("your_api_key", "your_database_url");

                        // Get a record by ID
                        var recordToUpdate = sdk.GetRecordById(1); // Replace 1 with the actual ID

                        if (recordToUpdate != null)
                        {
                            // Update the record
                            recordToUpdate.Value = 456;

                            try
                            {
                                sdk.UpdateRecord(recordToUpdate);
                                Console.WriteLine("Record updated successfully.");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"Error updating record: {ex.Message}");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Record not found.");
                        }
                    }
                }
                ```
                

Delete - Removing a Record

This example shows how to delete a record from the database.

C# Code Example

                ```csharp
                using SDKNamespace;
                using System;

                public class Example
                {
                    public static void Main(string[] args)
                    {
                        // Initialize SDK instance
                        var sdk = new SDKClient("your_api_key", "your_database_url");

                        // Get a record by ID
                        var recordToDelete = sdk.GetRecordById(2); // Replace 2 with the actual ID

                        if (recordToDelete != null)
                        {
                            try
                            {
                                sdk.DeleteRecord(recordToDelete);
                                Console.WriteLine("Record deleted successfully.");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"Error deleting record: {ex.Message}");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Record not found.");
                        }
                    }
                }
                ```
                
```