سلام بر تمامی برنامه نویسان سی شارپ 😉 در این پست کد ساخت SqlCommand با sql query و SqlConnection در سی شارپ را آماده کردم. انشاالله که این کد سی شارپ براتون مفید باشد.
خروجی پروژه:
Command created and connected.
Number of Employees is 4
Connection Closed.
Number of Employees is 4
Connection Closed.
کد ساخت SqlCommand با sql query و SqlConnection در سی شارپ :
using System;
using System.Data;
using System.Data.SqlClient;
class CommandScalar
{
static void Main()
{
SqlConnection conn = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
string sql = @"select count(*) from employee";
SqlCommand cmd = new SqlCommand(sql, conn);
Console.WriteLine("Command created and connected.");
try
{
conn.Open();
using System.Data;
using System.Data.SqlClient;
class CommandScalar
{
static void Main()
{
SqlConnection conn = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
string sql = @"select count(*) from employee";
SqlCommand cmd = new SqlCommand(sql, conn);
Console.WriteLine("Command created and connected.");
try
{
conn.Open();