http://www.worlduc.com/blog2012.aspx?bid=730767
Using C#sqlserver to realize adding and deleting
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Data;
Using SYSTEM.DATA.SQL;
Using System.Data.SqlClient;
Namespace ConsoleApplication2
{
Class Program
{
static void Main (string[] args)
{
while (true)
{
SqlConnection con = new SqlConnection ();
con. ConnectionString = "server=505-03;database=ttt;user=sa;pwd=123";
con. Open ();
SqlCommand cmd = New SqlCommand ();
cmd. Connection = con;
string Sql= "";
Console.WriteLine ("Increase please enter 1; Delete Please enter 2; modify please enter 3; find Please enter 4");
int i = Convert.ToInt32 (Console.ReadLine ());
String str = "";
Switch (i)
{
Case 1:
sql = "INSERT INTO";
Console.WriteLine ("Please enter the table you want to modify");
str = Console.ReadLine ();
SQL + = str + "(";
Console.WriteLine ("Please enter the name of the column you want to modify, separated by commas");
str = Console.ReadLine ();
SQL + = str + ")";
Console.WriteLine ("Please enter the corresponding data, separated by commas");
str = Console.ReadLine ();
SQL + = "VALUES (" + str+ ")";
Break
Case 2:
sql = "DELETE from";
Console.WriteLine ("Please enter the table name");
str = Console.ReadLine ();
SQL + = str;
Console.WriteLine ("Please enter the conditions for deletion");
str = Console.ReadLine ();
SQL + = "where" + str;
Break
Case 3:
sql = "UPDATE";
Console.WriteLine ("Please enter the table name");
str = Console.ReadLine ();
SQL + = str + "set";
Console.WriteLine ("Please enter data to be modified, such as money=0, multiple separated by commas");
str = Console.ReadLine ();
SQL + = str;
Console.WriteLine ("Please enter the conditions to be modified");
str = Console.ReadLine ();
SQL + = "where" + str;
Break
Case 4:
sql = "Select";
Console.WriteLine ("Please enter the name of the column you want to query, multiple separated by commas");
str = Console.ReadLine ();
SQL + = str;
Console.WriteLine ("Please enter the name of the table you want to query, multiple separated by commas");
str = Console.ReadLine ();
SQL + = "from" + str;
Break
}
Cmd.commandtext = SQL;
Cmd.commandtype = CommandType.Text;
Cmd. ExecuteNonQuery ();
}
}
}
}
C # change and delete SQL Server database