Exemple #1
0
		public DataTable LoadDataTable (IDbCommand dbcmd) 
		{
			string status = String.Empty;

			SqlSharpDataAdapter adapter = new SqlSharpDataAdapter (dbcmd);
			DataTable dataTable = new DataTable ();

			int rowsAddedOrRefreshed = 0;
			IDataReader reader = null;
			
			try {
				reader = dbcmd.ExecuteReader ();
				if (reader.FieldCount > 0)
					rowsAddedOrRefreshed = adapter.FillTable (dataTable, reader);
			}
			catch(Exception sqle) {
				status = "Error: " + sqle.Message;
			}

			if (status.Equals(String.Empty)) {
				int rowsAffected = reader.RecordsAffected;
				int fields = ((IDataRecord) reader).FieldCount;

				if (fields > 0) {
					status = "Rows Selected: " + rowsAddedOrRefreshed +
						"  Fields: " + fields;
				}
				else {
					status = "Rows Affected: " + rowsAffected;
				}
			}
			AppendText ("Status: " + status);
			
			if (reader != null && ! reader.IsClosed) {
				reader.Close();
			}
			adapter.Dispose();
			adapter = null;

			return dataTable;
		}
Exemple #2
0
		public DataTable LoadDataTable (IDbCommand dbcmd) 
		{
			string status = String.Empty;

			AppendText("Create DbDataAdapter...");
			SqlSharpDataAdapter adapter = new SqlSharpDataAdapter (dbcmd);
			
			AppendText("Create DataTable...");
			DataTable dataTable = new DataTable ();

			AppendText("Fill data into DataTable via DbDataAdapter...");

			int rowsAddedOrRefreshed = 0;
			IDataReader reader = null;
			
			try {
				reader = dbcmd.ExecuteReader ();
				if (reader.FieldCount > 0)
					rowsAddedOrRefreshed = adapter.FillTable (dataTable, reader);
			}
			catch(Exception sqle) {
				status = "Error: " + sqle.Message;
			}

			if (status.Equals(String.Empty)) {
				AppendText("Rows successfully Added or Refreshed in the DataTable: " + 
					rowsAddedOrRefreshed);
				int rowsAffected = reader.RecordsAffected;
				AppendText("Rows Affected: " + rowsAffected);

				int fields = ((IDataRecord) reader).FieldCount;
				AppendText("Field Count: " + fields);
			
				if (fields > 0) {
					status = "Rows Selected: " + rowsAddedOrRefreshed +
						"  Fields: " + fields;
				}
				else {
					status = "Rows Modified: " + rowsAffected;
				}
			}
			AppendText("Status: " + status);

			adapter.Dispose();
			adapter = null;

			AppendText("Return DataTable...");
			return dataTable;
		}