本文整理汇总了C#中IDataReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.Close方法的具体用法?C# IDataReader.Close怎么用?C# IDataReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NDataReader
/// <summary>
/// Creates a NDataReader from a <see cref="IDataReader" />
/// </summary>
/// <param name="reader">The <see cref="IDataReader" /> to get the records from the Database.</param>
/// <param name="isMidstream"><see langword="true" /> if we are loading the <see cref="IDataReader" /> in the middle of reading it.</param>
/// <remarks>
/// NHibernate attempts to not have to read the contents of an <see cref="IDataReader"/> into memory until it absolutely
/// has to. What that means is that it might have processed some records from the <see cref="IDataReader"/> and will
/// pick up the <see cref="IDataReader"/> midstream so that the underlying <see cref="IDataReader"/> can be closed
/// so a new one can be opened.
/// </remarks>
public NDataReader(IDataReader reader, bool isMidstream)
{
ArrayList resultList = new ArrayList(2);
try
{
// if we are in midstream of processing a DataReader then we are already
// positioned on the first row (index=0)
if (isMidstream)
{
currentRowIndex = 0;
}
// there will be atleast one result
resultList.Add(new NResult(reader, isMidstream));
while (reader.NextResult())
{
// the second, third, nth result is not processed midstream
resultList.Add(new NResult(reader, false));
}
results = (NResult[]) resultList.ToArray(typeof(NResult));
}
catch (Exception e)
{
throw new ADOException("There was a problem converting an IDataReader to NDataReader", e);
}
finally
{
reader.Close();
}
}
示例2: ClientSearch
protected virtual void ClientSearch(object sender, System.EventArgs e)
{
try {
string sql = "SELECT * FROM clients WHERE id>=0 ";
if (this.EntryClientName.Text!="") sql+=" AND name='"+this.EntryClientName.Text+"'";
if (this.EntryClientSurname1.Text!="") sql+=" AND surname1='"+this.EntryClientSurname1.Text+"'";
if (this.EntryClientSurname2.Text!="") sql+=" AND surname2='"+this.EntryClientSurname2.Text+"'";
Console.WriteLine(sql);
IDbCommand dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = sql;
reader = dbcmd.ExecuteReader();
Client client;
int i=0;
while(reader.Read()) {
client=new Client((int)reader["id"],(string)reader["name"],(string)reader["surname1"],(string)reader["surname2"]);
searchResult.Add(i++,client);
Console.WriteLine(client.nomComplet());
}
if (i>0) {
Console.WriteLine("Client finded");
ClientWindow cw = new ClientWindow (dbcon,searchResult);
cw.Show ();
Console.WriteLine("Client finded 2");
this.Destroy();
}
reader.Close();
} catch (Exception ex) {
Console.WriteLine("ClientSearch: "+ex.Message);
reader.Close();
}
}
示例3: BulkCopyAllEmployees
// Add your own data access methods.
// This file should not get overridden
/// <summary>
/// Executes the BulkCopy process to load Employee Information from IVantage to a local Table
/// </summary>
/// <param name="allEmployees">IDataReader that contains all Employees loaded from IVantage</param>
public void BulkCopyAllEmployees(IDataReader allEmployees)
{
try
{
Database db = DatabaseFactory.CreateDatabase("OneSourceConnectionString");
db.ExecuteNonQuery(CommandType.Text, "truncate table CS_Employee_Load");
}
catch (Exception ex)
{
allEmployees.Close(); // Close DataReader when an exception occurs
throw new Exception("An error ocurred while truncating data from Employee Info (load).", ex);
}
string connString = ConfigurationManager.ConnectionStrings["OneSourceConnectionString"].ConnectionString;
using (SqlBulkCopy copy = new SqlBulkCopy(connString))
{
try
{
copy.DestinationTableName = "CS_Employee_Load";
copy.BulkCopyTimeout = 600;
copy.WriteToServer(allEmployees);
}
catch (Exception ex)
{
throw new Exception("An error ocurred when importing Employee Info (BulkCopy).", ex);
}
finally
{
allEmployees.Close();
}
}
}
示例4: GetPhotoInfo
public static PhotoInfo GetPhotoInfo(IDataReader reader)
{
if (reader.Read())
{
PhotoInfo pi = GetPhotoEntity(reader);
reader.Close();
return pi;
}
else
{
reader.Close();
return null;
}
}
示例5: LoadListFromReader
public static List<MonHoc> LoadListFromReader(IDataReader reader)
{
List<MonHoc> items = new List<MonHoc>();
try
{
while (reader.Read())
{
MonHoc item = new MonHoc();
try { item.MonHocGuid = new Guid(reader["MonHocGuid"].ToString()); }
catch { }
item.MonHocName = reader["MonHocName"].ToString();
item.MonHocID = reader["MonHocID"].ToString();
try { item.Userid = Convert.ToInt32(reader["Userid"].ToString()); }
catch { }
items.Add(item);
}
}
catch
{ }
finally
{
reader.Close();
}
return items;
}
示例6: closeReader
/// <summary>
/// Readerをcloseします。
/// </summary>
/// <param name="reader">close対象のreader</param>
protected void closeReader(IDataReader reader)
{
if (reader != null && !reader.IsClosed)
{
reader.Close();
}
}
示例7: FillFolderPermissionInfoList
private static ArrayList FillFolderPermissionInfoList(IDataReader dr)
{
ArrayList arr = new ArrayList();
try
{
while (dr.Read())
{
// fill business object
FolderPermissionInfo obj = FillFolderPermissionInfo(dr, false);
// add to collection
arr.Add(obj);
}
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}
finally
{
// close datareader
if (dr != null)
{
dr.Close();
}
}
return arr;
}
示例8: GetCategoryListEntity
public static List<CategoryInfo> GetCategoryListEntity(IDataReader reader)
{
List<CategoryInfo> categorylist = new List<CategoryInfo>();
while (reader.Read())
{
CategoryInfo cinfo = new CategoryInfo();
cinfo.Cid = TypeConverter.ObjectToInt(reader["cid"], 0);
cinfo.Name = reader["name"].ToString();
cinfo.Parentid = TypeConverter.ObjectToInt(reader["parentid"].ToString(), 0);
cinfo.Parentlist = reader["parentlist"].ToString();
cinfo.Cg_img = reader["cg_img"].ToString();
cinfo.Sort = TypeConverter.ObjectToInt(reader["sort"].ToString(), 0);
cinfo.Cg_prefix = reader["cg_prefix"].ToString();
cinfo.Cg_status = TypeConverter.ObjectToInt(reader["cg_status"].ToString(), 0);
cinfo.Displayorder = TypeConverter.ObjectToInt(reader["displayorder"].ToString(), 0);
cinfo.Haschild = reader["haschild"].ToString() == "True" ? 1 : 0;
cinfo.Cg_relatetype = reader["cg_relatetype"].ToString();
cinfo.Cg_relateclass = reader["cg_relateclass"].ToString();
cinfo.Cg_relatebrand = reader["cg_relatebrand"].ToString();
cinfo.Cg_desc = reader["cg_desc"].ToString();
cinfo.Cg_keyword = reader["cg_keyword"].ToString();
cinfo.Goodcount = TypeConverter.ObjectToInt(reader["goodcount"].ToString(), 0);
categorylist.Add(cinfo);
}
reader.Close();
return categorylist;
}
示例9: CloseDataReader
internal static void CloseDataReader( IDataReader rd )
{
if (rd == null) return;
if (rd.IsClosed) return;
rd.Close();
}
示例10: PopulateObjectWithJoinCustom
/// <summary>
/// Takes an prepopulated IDataReader and creates an array of ChatMessages
/// </summary>
public static List<ChatMessage> PopulateObjectWithJoinCustom(IDataReader dr)
{
ColumnFieldList list = new ColumnFieldList(dr);
List<ChatMessage> arr = new List<ChatMessage>();
ChatMessage obj;
while (dr.Read())
{
obj = new ChatMessage();
if (list.IsColumnPresent("ChatMessageID")) { obj._chatMessageID = (int)dr["ChatMessageID"]; }
if (list.IsColumnPresent("ChatMessageWebID")) { obj._chatMessageWebID = (string)dr["ChatMessageWebID"]; }
if (list.IsColumnPresent("MemberIDFrom")) { obj._memberIDFrom = (int)dr["MemberIDFrom"]; }
if (list.IsColumnPresent("MemberIDTo")) { obj._memberIDTo = (int)dr["MemberIDTo"]; }
if (list.IsColumnPresent("Message")) { obj._message = (string)dr["Message"]; }
if (list.IsColumnPresent("Delivered")) { obj._delivered = (bool)dr["Delivered"]; }
if (list.IsColumnPresent("DTCreated")) { obj._dTCreated = (DateTime)dr["DTCreated"]; }
if (list.IsColumnPresent("WebMemberIDFrom")) { obj.WebMemberIDFrom = (String)dr["WebMemberIDFrom"]; }
arr.Add(obj);
}
dr.Close();
return arr;
}
示例11: FillTabPermissionCollection
private TabPermissionCollection FillTabPermissionCollection( IDataReader dr )
{
TabPermissionCollection arr = new TabPermissionCollection();
try
{
TabPermissionInfo obj = null;
while( dr.Read() )
{
// fill business object
obj = FillTabPermissionInfo( dr, false );
// add to collection
arr.Add( obj );
}
}
catch( Exception exc )
{
Exceptions.LogException( exc );
}
finally
{
// close datareader
if( dr != null )
{
dr.Close();
}
}
return arr;
}
示例12: InMemoryDataReader
/// <summary>
/// Creates an InMemoryDataReader from a <see cref="IDataReader" />
/// </summary>
/// <param name="reader">The <see cref="IDataReader" /> which holds the records from the Database.</param>
public InMemoryDataReader(IDataReader reader)
{
ArrayList resultList = new ArrayList();
try
{
_currentResultIndex = 0;
_currentRowIndex = 0;
resultList.Add( new InMemoryResultSet( reader, true ) );
while( reader.NextResult() )
{
resultList.Add( new InMemoryResultSet( reader, false ) );
}
_results = ( InMemoryResultSet[ ] ) resultList.ToArray( typeof( InMemoryResultSet ) );
}
catch( Exception e )
{
throw new DataMapperException( "There was a problem converting an IDataReader to an InMemoryDataReader", e );
}
finally
{
reader.Close();
reader.Dispose();
}
}
示例13: Start
// Use this for initialization
void Start()
{
OpenDB("MakingTime.db");
_dbcm = _dbc.CreateCommand();
//Insert data
sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Date',1,1,0,3,2,3,1,'Robert','Social')";
_dbcm.CommandText = sqlQuery;
_dbcm.ExecuteNonQuery();
sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Party',1,1,0,3,2,3,1,'Gina','Social')";
_dbcm.CommandText = sqlQuery;
_dbcm.ExecuteNonQuery();
sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Movie',1,1,0,3,2,3,1,'Robert','Social')";
_dbcm.CommandText = sqlQuery;
_dbcm.ExecuteNonQuery();
sqlQuery = "select * from Event";
_dbcm.CommandText = sqlQuery;
_dbr = _dbcm.ExecuteReader();
while (_dbr.Read())
{
Debug.Log("****** Data: " + _dbr["name"] + "\tday: " + _dbr["current_day"] + "\tTime: " + _dbr["current_time"] + "\tMin Day: " + _dbr["min_day"]
+ "\tMax Day: " + _dbr["max_day"] + "\tMin Time: " + _dbr["min_time"] + "\tMax Time: " + _dbr["max_time"] + "\tScheduled: " + _dbr["scheduled"]
+ "\tcreator: " + _dbr["creator"] + "\ttype: " + _dbr["type"]);
}
_dbr.Close();
_dbr = null;
_dbcm.Dispose();
_dbcm = null;
_dbc.Close();
_dbc = null;
}
示例14: DataReaderToDataSet
public static DataSet DataReaderToDataSet(IDataReader reader)
{
var ds = new DataSet();
DataTable table;
do
{
int fieldCount = reader.FieldCount;
table = new DataTable();
for (int i = 0; i < fieldCount; i++)
{
table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}
table.BeginLoadData();
var values = new Object[fieldCount];
while (reader.Read())
{
reader.GetValues(values);
table.LoadDataRow(values, true);
}
table.EndLoadData();
ds.Tables.Add(table);
} while (reader.NextResult());
reader.Close();
return ds;
}
示例15: ReadRandomNewCommitment
public static void ReadRandomNewCommitment(string event_Type, ref string name, ref int time_Length,
ref int maxTime, ref int minTime)
{
OpenDB("MakingTime.db");
_dbcm = _dbc.CreateCommand();
sqlQuery = "select count(*) as NumberOfRegions from Event_Type where Category = '" + event_Type + "'";
_dbcm.CommandText = sqlQuery;
Int32 rows = Convert.ToInt32(_dbcm.ExecuteScalar());
sqlQuery = "select * from Event_Type where Category = '" + event_Type + "'";
_dbcm.CommandText = sqlQuery;
_dbr = _dbcm.ExecuteReader();
int commitmentRow = UnityEngine.Random.Range(0, rows);
//Question
for(int countRows = 0; countRows < commitmentRow + 1; countRows += 1)
{
_dbr.Read();
}
name = _dbr.GetString(0);
time_Length = _dbr.GetInt32(1);
maxTime = _dbr.GetInt32(8);
minTime = _dbr.GetInt32(7);
_dbr.Close();
_dbr = null;
_dbcm.Dispose();
_dbcm = null;
_dbc.Close();
_dbc = null;
}