本文整理匯總了C#中System.Data.DataTable類的典型用法代碼示例。如果您正苦於以下問題:C# DataTable類的具體用法?C# DataTable怎麽用?C# DataTable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataTable類屬於System.Data命名空間,在下文中一共展示了DataTable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Sehirler
public static DataTable Sehirler()
{
try
{
using (baglan = new SqlConnection(ConnectionString))
{
baglan.Open();
using (komutver = new SqlCommand())
{
komutver.Connection = baglan;
komutver.CommandText = "sehir_Listele";
komutver.CommandType = CommandType.StoredProcedure;
adp = new SqlDataAdapter(komutver);
dt = new DataTable();
adp.Fill(dt);
}
}
}
catch (Exception)
{
throw;
}
return dt;
}
示例2: GetInvoiceNoCorrespondingtoLedgerForPurchaseReturnReport
/// <summary>
/// Get InvoiceNo Corresponding to Ledger For PurchaseReturn Register
/// </summary>
/// <param name="decLedgerId"></param>
/// <returns></returns>
public List<DataTable> GetInvoiceNoCorrespondingtoLedgerForPurchaseReturnReport(decimal decLedgerId, decimal decVoucherId)
{
List<DataTable> ListObj = new List<DataTable>();
DataTable dtbl = new DataTable();
try
{
if (sqlcon.State == ConnectionState.Closed)
{
sqlcon.Open();
}
SqlDataAdapter sqldataadapter = new SqlDataAdapter("GetInvoiceNoCorrespondingtoLedgerForPurchaseReturnReport", sqlcon);
sqldataadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter sqlparameter = new SqlParameter();
sqlparameter = sqldataadapter.SelectCommand.Parameters.Add("@ledgerId", SqlDbType.Decimal);
sqlparameter.Value = decLedgerId;
sqlparameter = sqldataadapter.SelectCommand.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
sqlparameter.Value = decVoucherId;
sqldataadapter.Fill(dtbl);
ListObj.Add(dtbl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
sqlcon.Close();
}
return ListObj;
}
示例3: GetReady
public void GetReady ()
{
dataTable = new DataTable ("itemTable");
dc1 = new DataColumn ("itemId");
dc2 = new DataColumn ("itemName");
dc3 = new DataColumn ("itemPrice");
dc4 = new DataColumn ("itemCategory");
dataTable.Columns.Add (dc1);
dataTable.Columns.Add (dc2);
dataTable.Columns.Add (dc3);
dataTable.Columns.Add (dc4);
DataRow dr;
seed = 123;
rowCount = 5;
rndm = new Random (seed);
for (int i = 1; i <= rowCount; i++) {
dr = dataTable.NewRow ();
dr["itemId"] = "item " + i;
dr["itemName"] = "name " + rndm.Next ();
dr["itemPrice"] = "Rs. " + (rndm.Next () % 1000);
dr["itemCategory"] = "Cat " + ((rndm.Next () % 10) + 1);
dataTable.Rows.Add (dr);
}
dataTable.AcceptChanges ();
dataView = new DataView (dataTable);
dataView.ListChanged += new ListChangedEventHandler (OnListChanged);
listChangedArgs = null;
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
var datos = new DataTable();
datos.Columns.Add("Nombre");
datos.Columns.Add("Activo");
var row = datos.NewRow();
row["Nombre"] = "Palma";
row["Activo"] = "Si";
datos.Rows.Add(row);
row = datos.NewRow();
row["Nombre"] = "Caucho";
row["Activo"] = "Si";
datos.Rows.Add(row);
row = datos.NewRow();
row["Nombre"] = "Café";
row["Activo"] = "Si";
datos.Rows.Add(row);
ViewState["Datos"] = datos;
ViewState["ckbActivarFiltro"] = "";
}
示例5: BindGridView
private void BindGridView()
{
CommonDao<Safezhuan> newmgr = new CommonDao<Safezhuan>();
DataTable dt = new DataTable();
dt = newmgr.FindDataTableByCondition("");
if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
GridViewEmployee.DataSource = dt;
GridViewEmployee.DataBind();
int columnCount = dt.Columns.Count;
GridViewEmployee.Rows[0].Cells.Clear();
GridViewEmployee.Rows[0].Cells.Add(new TableCell());
GridViewEmployee.Rows[0].Cells[0].ColumnSpan = columnCount + 1;
GridViewEmployee.Rows[0].Cells[0].Text = "沒有記錄";
GridViewEmployee.Rows[0].Cells[0].Style.Add("text-align", "center");
}
else
{
GridViewEmployee.DataSource = dt;
GridViewEmployee.DataBind();
}
}
示例6: GetTiposVenda
private DataTable GetTiposVenda()
{
DataTable dataTable = new DataTable();
this.con = new SqlConnection(Security.GetCnn());
string selectCommandText = "";
if (this._dev != "D")
{
selectCommandText = "select tipo_venta_id, descripcion, devolucion from Tipo_venta where devolucion='N'";
}
else
{
selectCommandText = "select tipo_venta_id, descripcion, devolucion from Tipo_venta where devolucion='S'";
}
if ((this.con != null) && (this.con.State == ConnectionState.Open))
{
this.con.Close();
}
this.con.Open();
try
{
new SqlDataAdapter(selectCommandText, this.con).Fill(dataTable);
this.con.Close();
}
catch (Exception)
{
}
return dataTable;
}
示例7: GetAllCidades
public static DataTable GetAllCidades(int estado_id)
{
DataTable retorno = new DataTable();
StringBuilder SQL = new StringBuilder();
SQL.Append(@"SELECT CidadeId, Nome FROM Cidade WHERE EstadoId = @ESTADO_ID");
try
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Mendes_varejo"].ConnectionString))
{
connection.Open();
SqlCommand command = new SqlCommand(SQL.ToString(), connection);
command.Parameters.AddWithValue("@ESTADO_ID", estado_id);
command.ExecuteNonQuery();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(retorno);
}
}
catch (Exception erro)
{
throw erro;
}
return retorno;
}
示例8: LoadData
public void LoadData()
{
GridTable = new DataTable("FalseX2011-07");
GridTable = MyCL.LoadDataTable("Select knowID, know From CDknow");
gridControlMain.DataSource = GridTable;
gridControlMain.RefreshDataSource();
}
示例9: Write
public void Write(DataTable table)
{
Log.Debug(String.Format("Writing {0} {1} to database..", table.Rows.Count, "record".Pluralize(table.Rows.Count)));
// Reopen connection, if it has closed for some reason.
if (!Adapter.IsConnectionOpen())
{
Adapter.OpenConnection();
}
// Manage dynamic table creation/management, if requested.
if (!isInitialized)
{
DbTableManager.InitializeTable(Adapter, table, tableInitializationOptions);
isInitialized = true;
}
// Write all rows in table.
int numRecordsWritten = 0;
foreach (DataRow row in table.Rows)
{
try
{
Adapter.InsertRow(table.TableName, row);
numRecordsWritten++;
}
catch (DbException) { }
}
Log.Debug(String.Format("Finished writing {0} {1}!", numRecordsWritten, "record".Pluralize(numRecordsWritten)));
}
示例10: ConvertToDataTable
void ConvertToDataTable()
{
ISheet sheet = hssfworkbook.GetSheetAt(0);
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
DataTable dt = new DataTable();
for (int j = 0; j < 5; j++)
{
dt.Columns.Add(Convert.ToChar(((int)'A')+j).ToString());
}
while (rows.MoveNext())
{
IRow row = (HSSFRow)rows.Current;
DataRow dr = dt.NewRow();
for (int i = 0; i < row.LastCellNum; i++)
{
ICell cell = row.GetCell(i);
if (cell == null)
{
dr[i] = null;
}
else
{
dr[i] = cell.ToString();
}
}
dt.Rows.Add(dr);
}
dataSet1.Tables.Add(dt);
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
#region Properties For The Base Class and Check Login
LoginID = Request.QueryString["LoginID"];
LoginInfo = CCLib.Login.GetLoginInfo(LoginID);
Redirect();
PageTitle = GetPortText(5372, false);
Section = "portfolio_tool";
CSS = "student";
HeadTag = "<STYLE TYPE='TEXT/CSS'><!--.btnDescription { font: 11px Verdana, Arial, Helvetica, sans-serif; margin: 0px 15px}--></STYLE>";
BodyTag = " alink='#990000' style='background-image:url(/media/shared/bg_left_bar_grey.gif);background-repeat:repeat-y;' bgcolor='#ffffff' leftmargin=0 link='#003366' text='#000000' topmargin=0 vlink='#003366' marginwidth='0' marginheight='0'";
LeftBar = "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='0'><TR VALIGN='TOP' BGCOLOR='#669966'><td background='/media/portfolio_tool/bg_bar_tan_top.gif'><img height=23 src='/media/student_parent/icons/icon_arrow.gif' alt='' width=24><img height=23 src='/media1/" + this.PortType + "/h_h_main" + this.SuffixCode() + ".gif' alt='' width=141>";
#endregion Properties For The Base Class and Check Login
#region Initialize Values and Form Execution
CheckPortSession();
if (!Page.IsPostBack)
{
strSQL = "select c.SectionNameCapital" + SuffixCode() + " Ability,Convert(varchar(10),DBO.fn_ConvertTimeZone(StartTime," + PortInfo["SchoolID"].ToString() + ",1),101) [Test Date], Percentile,CorrectAnswers Correct,TotalQuestions,a.APTestID from AP_SavedTest a join AP_SavedSection b on a.APTestID = b.APTestID join AP_Section c on b.SectionID = c.SectionID where PortfolioID = " + PortInfo["PortfolioID"].ToString() + " and IsActiveStatus = 1 order by b.SectionID";
dtSummary = CCLib.Common.DataAccess.GetDataTable(strSQL);
// Prevent user manually change url from browser
if (dtSummary.Rows.Count == 0)
Response.Redirect("AP_Portfolio2.aspx?LoginID=" + LoginID);
if (dtSummary.Rows.Count > 0 && dtSummary.Rows.Count < 6)
Response.Redirect("AP_Portfolio3.aspx?LoginID=" + LoginID);
//Check if Matchmaker results deleted
divMM.Visible = false;
ClientStorage clientStorage = new ClientStorage();
clientStorage.Retrieve(LoginID);
if (clientStorage.AspectIndicator < 2)
{
divMM.Visible = true;
divLinkMM.Visible = false;
}
if (dtSummary.Rows[0]["Percentile"].ToString() == "")
{
UpdateScore();
strSQL = "select c.SectionNameCapital" + SuffixCode() + " Ability,Convert(varchar(10),DBO.fn_ConvertTimeZone(StartTime," + PortInfo["SchoolID"].ToString() + ",1),101) [Test Date], Percentile,CorrectAnswers Correct,TotalQuestions,a.APTestID from AP_SavedTest a join AP_SavedSection b on a.APTestID = b.APTestID join AP_Section c on b.SectionID = c.SectionID where PortfolioID = " + PortInfo["PortfolioID"].ToString() + " and SchoolID = " + PortInfo["SchoolID"].ToString() + " and IsActiveStatus = 1 order by b.SectionID";
dtSummary = CCLib.Common.DataAccess.GetDataTable(strSQL);
}
rptSummary.DataSource = dtSummary;
rptSummary.DataBind();
AssignToUserControl();
}
#endregion Initialize Values and Form Execution
#region Properties For The Individual Base Class
SetCustomJS();
PortTitle = GetPortText(5372,false);
SetTitleBar();
SetLeftButtons();
PortSubTitle = GetPortText(8804, false);
SetSubTitleBar();
SetFooter();
#endregion Properties For The Individual Base Class
}
示例12: SetDSInfo
internal static void SetDSInfo(DataTable dsTable) {
DataRow row = dsTable.NewRow();
row["TypeName"] = "SMALLINT";
row["ProviderDbType"] = MySqlDbType.Int16;
row["ColumnSize"] = 0;
row["CreateFormat"] = "SMALLINT";
row["CreateParameters"] = null;
row["DataType"] = "System.Int16";
row["IsAutoincrementable"] = true;
row["IsBestMatch"] = true;
row["IsCaseSensitive"] = false;
row["IsFixedLength"] = true;
row["IsFixedPrecisionScale"] = true;
row["IsLong"] = false;
row["IsNullable"] = true;
row["IsSearchable"] = true;
row["IsSearchableWithLike"] = false;
row["IsUnsigned"] = false;
row["MaximumScale"] = 0;
row["MinimumScale"] = 0;
row["IsConcurrencyType"] = DBNull.Value;
row["IsLiteralsSupported"] = false;
row["LiteralPrefix"] = null;
row["LiteralSuffix"] = null;
row["NativeDataType"] = null;
dsTable.Rows.Add(row);
}
示例13: BindToColumns
private void BindToColumns(DataTable metaData)
{
if(false == _fieldsBound)
{
if(metaData.Columns.Contains("TABLE_CATALOG")) f_Catalog = metaData.Columns["TABLE_CATALOG"];
if(metaData.Columns.Contains("TABLE_SCHEMA")) f_Schema = metaData.Columns["TABLE_SCHEMA"];
if(metaData.Columns.Contains("TABLE_NAME")) f_TableName = metaData.Columns["TABLE_NAME"];
if(metaData.Columns.Contains("INDEX_CATALOG")) f_IndexCatalog = metaData.Columns["INDEX_CATALOG"];
if(metaData.Columns.Contains("INDEX_SCHEMA")) f_IndexSchema = metaData.Columns["INDEX_SCHEMA"];
if(metaData.Columns.Contains("INDEX_NAME")) f_IndexName = metaData.Columns["INDEX_NAME"];
if(metaData.Columns.Contains("UNIQUE")) f_Unique = metaData.Columns["UNIQUE"];
if(metaData.Columns.Contains("CLUSTERED")) f_Clustered = metaData.Columns["CLUSTERED"];
if(metaData.Columns.Contains("TYPE")) f_Type = metaData.Columns["TYPE"];
if(metaData.Columns.Contains("FILL_FACTOR")) f_FillFactor = metaData.Columns["FILL_FACTOR"];
if(metaData.Columns.Contains("INITIAL_SIZE")) f_InitializeSize = metaData.Columns["INITIAL_SIZE"];
if(metaData.Columns.Contains("NULLS")) f_Nulls = metaData.Columns["NULLS"];
if(metaData.Columns.Contains("SORT_BOOKMARKS")) f_SortBookmarks = metaData.Columns["SORT_BOOKMARKS"];
if(metaData.Columns.Contains("AUTO_UPDATE")) f_AutoUpdate = metaData.Columns["AUTO_UPDATE"];
if(metaData.Columns.Contains("NULL_COLLATION")) f_NullCollation = metaData.Columns["NULL_COLLATION"];
if(metaData.Columns.Contains("COLLATION")) f_Collation = metaData.Columns["COLLATION"];
if(metaData.Columns.Contains("CARDINALITY")) f_Cardinality = metaData.Columns["CARDINALITY"];
if(metaData.Columns.Contains("PAGES")) f_Pages = metaData.Columns["PAGES"];
if(metaData.Columns.Contains("FILTER_CONDITION")) f_FilterCondition = metaData.Columns["FILTER_CONDITION"];
if(metaData.Columns.Contains("INTEGRATED")) f_Integrated = metaData.Columns["INTEGRATED"];
}
}
示例14: Ilceler
public static DataTable Ilceler(int id)
{
try
{
using (baglan = new SqlConnection(ConnectionString))
{
baglan.Open();
using (komutver = new SqlCommand())
{
komutver.Connection = baglan;
komutver.CommandText = "ilce_Listele";
komutver.Parameters.Add("@ilceId", SqlDbType.Int);
komutver.Parameters["@ilceId"].Value = Convert.ToInt32(id);
komutver.CommandType = CommandType.StoredProcedure;
adp = new SqlDataAdapter(komutver);
dt = new DataTable();
adp.Fill(dt);
}
}
}
catch (Exception)
{
throw;
}
return dt;
}
示例15: ExcuteSQLBulkCopy
public void ExcuteSQLBulkCopy(DataTable Datatable, string TableName, ConnectionState connectionstate, ref bool executionSucceeded)
{
try
{
if (objConnection.State == System.Data.ConnectionState.Closed)
{
objConnection.Open();
}
SqlBulkCopy.BatchSize = Datatable.Rows.Count;
SqlBulkCopy.BulkCopyTimeout = 0;
SqlBulkCopy.DestinationTableName = TableName;
SqlBulkCopy.WriteToServer(Datatable);
SqlBulkCopy.Close();
executionSucceeded = true;
}
catch (Exception ex)
{
executionSucceeded = false;
HandleExceptions(ex);
}
finally
{
//SqlBulkCopy.ColumnMappings.Clear();
if (connectionstate == ConnectionState.CloseOnExit)
{
if (objConnection.State == System.Data.ConnectionState.Open)
{
objConnection.Close();
}
}
}
}