SqlDataReader converted to string with space problem Believe that a lot of friends in the Database tutorial field and TextBox.Text attribute value comparison, the read out of the SqlDataReader object to string, found that even if the same value does not produce an equal result, the breakpoint method to view the results, the original SqlDataReader converted to string , the field type size is padded with a space, and then the space can be compared by using the trim () function of the string. This is because the database uses the Nvhar type, when write value than the specified value hours will be filled with space, so you should pay attention to remove the space problem.
Provides a way to read only incoming streams of rows from a SQL Server database. This class cannot be inherited.
Namespaces: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)
Statement
Public
class SqlDataReader
Inherits DbDataReader
Implements IDataReader, IDisposable, IDataRecord
' Usage
Dim instance As SqlDataReader
J #
Copy
Public
Class SqlDataReader extends DbDataReader implements IDataReader, IDisposable,
IDataRecord
Using the SqlDataReader problem
The first question, DataReader's Read () method is sequential read, which can refer to the pointer, the first pointer to the head of the DataReader, but there is no data, reader data from the next address, if you want to get data need to use Read () to fetch.
The second question, HasRows, is whether to return the DataReader containing one or more results, and if so, tell the program that the department already exists.
The understanding here is that the data in DataReader no matter how many, he exists, just like you stand in front of a team, see is always the first person, if he does not walk away, you can not see the next person, but the number of the team will not because you do not see the change.
Application examples
public static SqlDataReader ExecuteReader (String str)
{
Using (SqlConnection conn=new SqlConnection ())
{
Try
{
conn = CreateConnection ();
if (conn.state = = connectionstate.closed) Conn.Open ();
SqlCommand cmd = new SqlCommand (STR, conn);
SqlDataReader reader = Cmd.executereader (commandbehavior.closeconnection);
return reader;
}
Catch
{
Conn.close ();
}
}
}
SqlDataReader can think of a forward only curosor. It's not like a dataset is a disconnected data link. It has been occupying connection [that is, always saving links]