using System;
using System.Data;
using System.Data.SqlClient;
namespace ExecuteQueryNoResultSet
{
class Program
{
static void Main(string[] args)
{
string sqlConnectString = @"Data Source=Alfred-PC\SQLExpress;Integrated Security=SSPI;" +
"Initial Catalog=AdoDotNet35Cookbook;";
string sqlDelete = "DELETE FROM ExecuteQueryNoResultSet " +
"WHERE Id = 2";
//create and execute a command to delete the record with Id=2 from the table ExecuteQueryNoResultSet
SqlConnection connection = new SqlConnection(sqlConnectString);
SqlCommand command = new SqlCommand(sqlDelete, connection);
connection.Open();
int rowsAffected = command.ExecuteNonQuery();
Console.WriteLine("{0} row(s) affected.", rowsAffected);
Console.WriteLine("Record with Id = 2 deleted.");
connection.Close();
Console.ReadKey();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment