سلام بر برنامه نویسان عزیز 😉 در این مطلب کد Execute (اجرا کردن) دو sql command در سی شارپ #C را آماده کردم. انشاالله که این کد سی شارپ براتون مفید باشد.
کد Execute (اجرا کردن) دو sql command در سی شارپ #C :
using System;
using System.Data;
using System.Data.SqlClient;
class MainClass
{
public static void Main()
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = @"Data Source = .\sqlexpress;Database = Northwind; Integrated Security=SSPI";
using (SqlCommand com = con.CreateCommand())
{
com.CommandType = CommandType.Text;
com.CommandText = "SELECT BirthDate,FirstName,LastName FROM "+
"Employees ORDER BY BirthDate;SELECT * FROM Employees";
con.Open();
using (SqlDataReader reader = com.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(" {0,18:D} - {1} {2}",
reader.GetDateTime(0), // Retrieve typed data
reader["FirstName"], // Use string index
reader[2]); // Use ordinal index
}
using System.Data;
using System.Data.SqlClient;
class MainClass
{
public static void Main()
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = @"Data Source = .\sqlexpress;Database = Northwind; Integrated Security=SSPI";
using (SqlCommand com = con.CreateCommand())
{
com.CommandType = CommandType.Text;
com.CommandText = "SELECT BirthDate,FirstName,LastName FROM "+
"Employees ORDER BY BirthDate;SELECT * FROM Employees";
con.Open();
using (SqlDataReader reader = com.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(" {0,18:D} - {1} {2}",
reader.GetDateTime(0), // Retrieve typed data
reader["FirstName"], // Use string index
reader[2]); // Use ordinal index
}