本文整理汇总了C#中DataTable.Load方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.Load方法的具体用法?C# DataTable.Load怎么用?C# DataTable.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MySqlConnection
public int fjöldi_rada()
{
MySqlConnection connection;
string connectionString = "Server=10.0.105.33;Database=Leikur;Uid=first;Pwd=first;";
connection = new MySqlConnection(connectionString);
connection.Open();
string query = @"SELECT * FROM spilari";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
MySqlDataReader queryCommandReader = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(queryCommandReader);
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds, "SQL Temp Table");
adapter.Dispose();
cmd.Dispose();
return ds.Tables[0].Rows.Count;
}
示例2: Load_RowStateUpsertUnpresent
public void Load_RowStateUpsertUnpresent()
{
localSetup();
_dt.Rows.Add(new object[] { 4, "mono 4" });
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr, LoadOption.Upsert);
try
{
Assert.Equal(" ", dtLoad.Rows[3][1, DataRowVersion.Original]);
Assert.False(true);
}
catch (VersionNotFoundException)
{
}
}
示例3: Load_RowStateUpsertDuplicateKey2
public void Load_RowStateUpsertDuplicateKey2()
{
localSetup();
_dt.Rows.Add(new object[] { 4, "mono 4" });
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
dtLoad.Rows[2].Delete();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr, LoadOption.Upsert);
dtLoad.AcceptChanges();
try
{
Assert.Equal(" ", dtLoad.Rows[4][1]);
Assert.False(true);
}
catch (IndexOutOfRangeException)
{
}
}
示例4: GetData
private void GetData(string id)
{
if (iOldID != iDefaultChecked)
{
conn.Open();
dtReport = new DataTable();
dtReport.Load(new SqlCommand("SELECT Report FROM sysReport WHERE ID=" + id, conn).ExecuteReader());
bt = (byte[])dtReport.Rows[0]["Report"];
iOldID = iDefaultChecked;
conn.Close();
}
}
示例5: Load_MissingColsNullable
public void Load_MissingColsNullable()
{
localSetup();
DataTable dtLoad = new DataTable("LoadMissingCols");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.Columns.Add("missing", typeof(string));
dtLoad.Columns["missing"].AllowDBNull = true;
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 4, "mono 4", "miss4" });
dtLoad.Rows.Add(new object[] { 5, "mono 5", "miss5" });
dtLoad.Rows.Add(new object[] { 6, "mono 6", "miss6" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
Assert.Equal(3, dtLoad.Columns.Count);
Assert.Equal(6, dtLoad.Rows.Count);
Assert.Equal(4, dtLoad.Rows[0][0]);
Assert.Equal("mono 4", dtLoad.Rows[0][1]);
Assert.Equal("miss4", dtLoad.Rows[0][2]);
Assert.Equal(5, dtLoad.Rows[1][0]);
Assert.Equal("mono 5", dtLoad.Rows[1][1]);
Assert.Equal("miss5", dtLoad.Rows[1][2]);
Assert.Equal(6, dtLoad.Rows[2][0]);
Assert.Equal("mono 6", dtLoad.Rows[2][1]);
Assert.Equal("miss6", dtLoad.Rows[2][2]);
Assert.Equal(1, dtLoad.Rows[3][0]);
Assert.Equal("mono 1", dtLoad.Rows[3][1]);
//Assert.Null (dtLoad.Rows[3][2]);
Assert.Equal(2, dtLoad.Rows[4][0]);
Assert.Equal("mono 2", dtLoad.Rows[4][1]);
//Assert.Null (dtLoad.Rows[4][2]);
Assert.Equal(3, dtLoad.Rows[5][0]);
Assert.Equal("mono 3", dtLoad.Rows[5][1]);
//Assert.Null (dtLoad.Rows[5][2]);
}
示例6: Load_MissingColsNonNullable
public void Load_MissingColsNonNullable()
{
localSetup();
DataTable dtLoad = new DataTable("LoadMissingCols");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.Columns.Add("missing", typeof(string));
dtLoad.Columns["missing"].AllowDBNull = false;
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 4, "mono 4", "miss4" });
dtLoad.Rows.Add(new object[] { 5, "mono 5", "miss5" });
dtLoad.Rows.Add(new object[] { 6, "mono 6", "miss6" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
try
{
dtLoad.Load(dtr);
Assert.False(true);
}
catch (ConstraintException)
{
}
}
示例7: Load_ExtraColsNonEqualVal
public void Load_ExtraColsNonEqualVal()
{
localSetup();
DataTable dtLoad = new DataTable("LoadExtraCols");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 4 });
dtLoad.Rows.Add(new object[] { 5 });
dtLoad.Rows.Add(new object[] { 6 });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
Assert.Equal(2, dtLoad.Columns.Count);
Assert.Equal(6, dtLoad.Rows.Count);
Assert.Equal(4, dtLoad.Rows[0][0]);
Assert.Equal(5, dtLoad.Rows[1][0]);
Assert.Equal(6, dtLoad.Rows[2][0]);
Assert.Equal(1, dtLoad.Rows[3][0]);
Assert.Equal("mono 1", dtLoad.Rows[3][1]);
Assert.Equal(2, dtLoad.Rows[4][0]);
Assert.Equal("mono 2", dtLoad.Rows[4][1]);
Assert.Equal(3, dtLoad.Rows[5][0]);
Assert.Equal("mono 3", dtLoad.Rows[5][1]);
}
示例8: Load_IncompatibleEHandlerF
// Load doesn't have a third overload in System.Data
// and is commented-out below
public void Load_IncompatibleEHandlerF()
{
_fillErrCounter = 0;
_fillErr[0].init("LoadIncompatible", 1, false,
"Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
localSetup();
DataTable dtLoad = new DataTable("LoadIncompatible");
dtLoad.Columns.Add("name", typeof(double));
DataTableReader dtr = _dt.CreateDataReader();
try
{
dtLoad.Load(dtr, LoadOption.PreserveChanges, fillErrorHandler);
Assert.False(true);
}
catch (ArgumentException)
{
}
}
示例9: Load_IncompatibleEHandlerT
// Load doesn't have a third overload in System.Data
// and is commented-out below
public void Load_IncompatibleEHandlerT()
{
_fillErrCounter = 0;
_fillErr[0].init("LoadIncompatible", 1, true,
"Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
_fillErr[1].init("LoadIncompatible", 2, true,
"Input string was not in a correct format.Couldn't store <mono 2> in name Column. Expected type is Double.");
_fillErr[2].init("LoadIncompatible", 3, true,
"Input string was not in a correct format.Couldn't store <mono 3> in name Column. Expected type is Double.");
localSetup();
DataTable dtLoad = new DataTable("LoadIncompatible");
dtLoad.Columns.Add("name", typeof(double));
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr, LoadOption.PreserveChanges, fillErrorHandler);
}
示例10: Load_Incompatible
public void Load_Incompatible()
{
localSetup();
DataTable dtLoad = new DataTable("LoadIncompatible");
dtLoad.Columns.Add("name", typeof(double));
DataTableReader dtr = _dt.CreateDataReader();
try
{
dtLoad.Load(dtr);
Assert.False(true);
}
catch (ArgumentException)
{
}
}
示例11: Load_NoSchema
public void Load_NoSchema()
{
localSetup();
DataTable dtLoad = new DataTable("LoadNoSchema");
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
Assert.Equal(2, dtLoad.Columns.Count);
Assert.Equal(3, dtLoad.Rows.Count);
Assert.Equal(1, dtLoad.Rows[0][0]);
Assert.Equal("mono 1", dtLoad.Rows[0][1]);
Assert.Equal(2, dtLoad.Rows[1][0]);
Assert.Equal("mono 2", dtLoad.Rows[1][1]);
Assert.Equal(3, dtLoad.Rows[2][0]);
Assert.Equal("mono 3", dtLoad.Rows[2][1]);
}
示例12: Load_Basic
public void Load_Basic()
{
localSetup();
DataTable dtLoad = new DataTable("LoadBasic");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.Columns["id"].ReadOnly = true;
dtLoad.Columns["name"].ReadOnly = true;
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "load 1" });
dtLoad.Rows.Add(new object[] { 2, "load 2" });
dtLoad.Rows.Add(new object[] { 3, "load 3" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
Assert.Equal(2, dtLoad.Columns.Count);
Assert.Equal(3, dtLoad.Rows.Count);
Assert.Equal(1, dtLoad.Rows[0][0]);
Assert.Equal("mono 1", dtLoad.Rows[0][1]);
Assert.Equal(2, dtLoad.Rows[1][0]);
Assert.Equal("mono 2", dtLoad.Rows[1][1]);
Assert.Equal(3, dtLoad.Rows[2][0]);
Assert.Equal("mono 3", dtLoad.Rows[2][1]);
}
示例13: Load_RowStateChangesDefaultDelete
public void Load_RowStateChangesDefaultDelete()
{
localSetup();
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
dtLoad.Rows[2].Delete();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
try
{
Assert.Equal(" ", dtLoad.Rows[2][1, DataRowVersion.Current]);
Assert.False(true);
}
catch (VersionNotFoundException)
{
}
}
示例14: select_from
public string select_from()
{
MySqlConnection connection;
string connectionString = "Server=10.0.105.33;Database=Leikur;Uid=first;Pwd=first;";
connection = new MySqlConnection(connectionString);
connection.Open();
string query = @"SELECT * FROM spilari";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
MySqlDataReader queryCommandReader = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(queryCommandReader);
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds, "SQL Temp Table");
adapter.Dispose();
cmd.Dispose();
String rowText = string.Empty;
int topRows = ds.Tables[0].Rows.Count;
for (int i = 0; i < topRows; i++)
{
foreach (DataColumn column in dataTable.Columns)
{
rowText += dataTable.Rows[i][column.ColumnName] + "|";
}
rowText = rowText + "-";
}
connection.Close();
return rowText;
}
示例15: CreateMenu
/// <summary>
/// 初始化报表菜单
/// </summary>
private void CreateMenu()
{
//初始化报表类型
conn.Open();
dtReport = new DataTable();
dtReport.Load(new SqlCommand("SELECT * FROM sysReport WHERE ReportGUID='" + rpGUID + "' ORDER BY ReportName", conn).ExecuteReader());
tsmChooseDetail = new ToolStripMenuItem[dtReport.Rows.Count];
for (int i = 0; i < dtReport.Rows.Count; i++)
{
if (Convert.ToBoolean(dtReport.Rows[i]["IsDefault"]))
{
tsmChooseDetail.SetValue(new ToolStripMenuItem(dtReport.Rows[i]["ReportName"].ToString() + "(默认)"),i);
tsmChooseDetail[i].Name = dtReport.Rows[i]["ID"].ToString();
tsmChooseDetail[i].Checked = true;
iDefaultChecked = i;
iOldID = i;
bt = (byte[])dtReport.Rows[i]["Report"];
}
else
{
tsmChooseDetail.SetValue(new ToolStripMenuItem(dtReport.Rows[i]["ReportName"].ToString()), i);
tsmChooseDetail[i].Name = dtReport.Rows[i]["ID"].ToString();
}
}
conn.Close();
menubtnPrint = new ContextMenuStrip();
tsmPrintReport = new ToolStripMenuItem("打印");
tsmChooseReport = new ToolStripMenuItem("选择报表");
tsmDesginReport = new ToolStripMenuItem("设计报表");
tsmAddReport = new ToolStripMenuItem("新增报表");
tsmPreviewReport = new ToolStripMenuItem("打印预览");
ToolStripSeparator tss1 = new ToolStripSeparator();
ToolStripSeparator tss2 = new ToolStripSeparator();
tsmChooseReport.DropDownItems.AddRange(tsmChooseDetail);
menubtnPrint.Items.Add(tsmPrintReport);
menubtnPrint.Items.Add(tss1);
menubtnPrint.Items.Add(tsmChooseReport);
//权限控制,只有管理员才拥有设计报表和新增报表权限
if (sAuth == "admin")
{
menubtnPrint.Items.Add(tsmDesginReport);
menubtnPrint.Items.Add(tsmAddReport);
}
menubtnPrint.Items.Add(tss2);
menubtnPrint.Items.Add(tsmPreviewReport);
//代理打印预览事件
tsmPreviewReport.Click += new EventHandler(tsmPreviewReport_Click);
//代理报表设计事件
tsmDesginReport.Click += new EventHandler(tsmDesginReport_Click);
//代理选择报表事件
tsmChooseReport.DropDown.ItemClicked += new ToolStripItemClickedEventHandler(DropDown_ItemClicked);
//代理打印事件
tsmPrintReport.Click += new EventHandler(tsmPrintReport_Click);
//代理新增事件
tsmAddReport.Click += new EventHandler(tsmAddReport_Click);
}