I. Appending and deleting strings using the StringBuilder class
1. Creating an object of the StringBuilder class
StringBuilder sb=new StringBuilder ("Initial string value");
2.Append () Method stitching strings
Sb. Append ("hehe");
The result is: initial string value hehe
3. Insert a string at the specified location using the Insert () method
Sb. Insert (position, string);
Sb. Insert (2, "on");
The result is: Initialize the string value hehe
4. Use the Remove () method to delete a 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 properties: Determine if the data is read, true if there is data, false instead
2.Read () Method: Advances to the next row of read data
3.Close () Method: Close the 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. Manipulating data using the Excutenonquery () method of the Command object
Excutenonquery () is primarily used to modify and delete data
Case: Adding Grade information
StringBuilder sb = new StringBuilder ();
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 ();
Querying and manipulating data using ADO