First, you need to create a new table, in order to test with a student table
Once you've created a new table, you're ready to manipulate the database.
Lists the commonly used additions and deletions to search
Operation
static void Main (string[] args)
{
String str1= "";
SqlConnection Sqlcon = new SqlConnection ("Data source=.;i Nitial Catalog=db_user; Persist Security info=true; User Id=sa; Password=qwerty ");
SqlCommand sqlcom = new SqlCommand ();
Sqlcon. Open ();
Sqlcom. Connection = Sqlcon;
Console.WriteLine ("Please follow the instructions below");
Console.WriteLine ("1. Check all student Information");
Console.WriteLine ("2. Specify the age of the specified student");
Console.WriteLine ("3. Update student Information");
Console.WriteLine ("4. Delete Student Information");
Console.WriteLine ("5. Increase student Information");
String Check=console.readline ();
if (check = = "1")
{
Sqlcom.commandtext = "SELECT * from Tb_stu";
SqlDataReader read = sqlcom. ExecuteReader ();
while (read. Read ())
{
String a = read. GetValue (0). ToString ();
String a1 = read. GetValue (1). ToString ();
String a2 = read. GetValue (2). ToString ();
Console.WriteLine ("ID:" + A + "name:" + A1 + "Age:" + A2);
}
}
sqlcom = null;
Sqlcon. Close ();
Console.ReadLine ();
}
The inserted code
Sqlcom.commandtext = "INSERT into Tb_stu (name,age) VALUES ('" +name+ "', '" +age+ "')";
Code to remove
Sqlcom.commandtext = "Delete from Tb_stu where name=+ '" + name + "'";
Where Condition Query
Sqlcom.commandtext = "Update tb_stu set name= '" + str2+ "' Where Name= '" +name+ "'";
Update action
Sqlcom.commandtext = "Select age from Tb_stu where Name= '" +name+ "'";
about how to create a connection query database operation in the C # console window