-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathselect-top.cs
More file actions
48 lines (41 loc) · 1.47 KB
/
Copy pathselect-top.cs
File metadata and controls
48 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = "Your_Connection_String_Here";
string query = "SELECT TOP 1 OrderID, CustomerName, OrderDate FROM ORDERS";
DataTable ordersTable = FetchDataFromDatabase(connectionString, query);
if (ordersTable.Rows.Count > 0)
{
ProcessOrder(ordersTable.Rows[0]);
}
}
static DataTable FetchDataFromDatabase(string connectionString, string query)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
DataTable dataTable = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(dataTable);
}
return dataTable;
}
}
}
static void ProcessOrder(DataRow orderRow)
{
// This function processes each order
int orderId = Convert.ToInt32(orderRow["OrderID"]);
string customerName = orderRow["CustomerName"].ToString();
DateTime orderDate = Convert.ToDateTime(orderRow["OrderDate"]);
Console.WriteLine($"Processing Order: ID={orderId}, Customer={customerName}, Date={orderDate}");
// Add your specific order processing logic here
}
}