I. Appending and deleting strings using the StringBuilder class
1. Create an object of the StringBuilder class StringBuilder sb=new StringBuilder ("Initial string value"); The 2.Append () method stitching the string sb. Append ("hehe"); The result is: initial string value hehe 3. Insert the string SB at the specified location using the Insert () method. Insert (position, string); Sb. Insert (2, "on"); The result is: Initialize the string value Oh 4. Use the Remove () method to remove the string sb. Remove (start position, delete length) sb. Remove (7,2); The result is: Initialize the string value
Two. Datarader object read Data 1.HasRows property: Determine whether to read data, if there is data is true, and vice versa is False 2.Read () method: forward to the next row read Data 3.Close () method: Close DataReader Object
Case: StringBuilder sb = new StringBuilder ();
SelectCount (*) fromstudent
Sb. Appendline ("select");
Sb. Appendline ("[Studentno]");
Sb. Appendline (", [Studentname]");
Sb. Appendline ("from");
Sb. Appendline ("Student");
SqlCommand com = new SqlCommand (sb.) ToString (), con);
SqlDataReader dr=com. ExecuteReader ();
Determines whether the DataReader object returns a result, and if there is a return result hasrows the value is true, the loop reads
if (Dr. HasRows)
{
while (Dr. Read ())
{
Console.WriteLine ("Name:" + dr["studentname"] + "\ T Study number:" + dr["Studentno"]);
}
}
Close the DataReader object
Dr. Close (); Three. Use the Excutenonquery () method of the Command object to manipulate data excutenonquery () is primarily used for adding changes to data and deleting cases: Adding grade information StringBuilder SB = new Stringbuil Der ();
Sb. Appendline ("INSERT into");
Sb. Appendline ("Grade");
Sb. Appendline ("([Gradename])");
Sb. Appendline ("values");
Sb. Appendline ("('" +gradename+ "')");
SqlCommand com = new SqlCommand (sb.) ToString (), con);
int count=com. ExecuteNonQuery ();
The 14th Chapter uses ADO to query and manipulate data