我正在尝试DataTable在Sql Server上写入目标表.DataTable dt只包含一列及其调用Email.我的目标表中包含tpid,lastname,age,date和email.这是我用于批量复制的代码:
using (SqlConnection sqlConn = new SqlConnection(sqlCs))
{
sqlConn.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConn.ConnectionString, SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.UseInternalTransaction))
{
bulkCopy.DestinationTableName = destinationTableName;
bulkCopy.WriteToServer(dt);
}
}
Run Code Online (Sandbox Code Playgroud)
我看到的是,在我的目标表中,我从我的DataTable中获取了Email的值,tpid而不是插入到列中email.我这里没有使用列映射,但是不应该自动批量复制电子邮件与电子邮件匹配?
我在DataTable中有多个要删除的列.我目前有索引我要删除.例如,假设我有10列,我想删除索引4,8和9.
我知道我可以做类似这样的dataTable.Columns.RemoveAt(索引).但是,一旦我这样做,我删除了下一列的索引.
所以我的问题是如何删除预期的列,因为我只有列索引.
如何在managedbean中绑定primefaces数据表?怎么放数据,怎么放列?
我的bean类:
public class BeanTest implements Serializable{
private String name;
private String email;
private int age;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我的托管bean:
public class TestTable implements Serializable{
private DataTable tabela;
private List<BeanTest> lista;
@PostConstruct
public void init() {
int age= 18;
this.lista = new ArrayList<>();
this.lista.add(new BeanTest("name1", "email1", age));
this.lista.add(new BeanTest("name2", "email2", age++));
this.lista.add(new BeanTest("name3", "email3", age++));
this.tabela = new DataTable();
Column column1 = new Column();
column1.setHeaderText("Nome");
Column column2 = new Column();
column2.setHeaderText("Email");
Column column3 = new Column();
column3.setHeaderText("Idade");
this.getTabela().getChildren().add(column1);
this.getTabela().getChildren().add(column2); …Run Code Online (Sandbox Code Playgroud) 我正在使用.NET 4.5,当我这样做时:
DataTable table_DropDownSelections = new DataTable();
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2013上,我得到一条红线,上面写着:
找不到引用名称数据表的类型
当我这样做时:
using System.Data;
Run Code Online (Sandbox Code Playgroud)
我犯了同样的错误 .
Dot Net 4.5没有数据表?从MSDN我发现它确实如此.
谢谢
我将p:dataTable的paginatorTemplate取消了:
<p:dataTable id="lazyDataTable" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} {Exporters}">
Run Code Online (Sandbox Code Playgroud)
宣布"出口商":
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage libray ="images" name="excel.png"/>
<p:dataExporter type = "xls" target="lazyDataTable" fileName="report" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="pdf.png"/>
<p:dataExporter type = "pdf" target="lazyDataTable" fileName="report" />
</h:commandLink>
</f:facet>
Run Code Online (Sandbox Code Playgroud)
我希望导出器将与表头对齐,但它出现在标题的中间,如下所示:

如何将它与标题右侧对齐,谢谢!
我正在尝试删除/删除datatable有100行的1行,如下所示:
Form1.dt.Rows[i].Delete();
Form1.dt.AcceptChanges();
Run Code Online (Sandbox Code Playgroud)
但是当我得到表格的行数时,进一步向下:
int rc = Form1.dt.Rows.Count;
Run Code Online (Sandbox Code Playgroud)
rc仍然返回100!确实Form1.dt.Rows[i].Delete();清除行并将其留空或从表中完全删除行?我该如何删除该行dt?
我尝试做的是在数据表中渲染条形图.我正在使用Highchart和DataTable jquery插件.基本上我想做的就是这个.请看下面的链接.
我有3个列的表,其中一个列中有条形图.该表是可排序的,它具有分页以显示更多行.一切都很难过,有什么办法以某种方式循环图表系列并显示一个用于eatch行.
谢谢您的帮助
我正在创建一个返回值datatable 和一个int值的方法.我创建了一个只返回的方法datatable.请查看代码
public static DataTable ShutterstockSearchResults(string url)
{
int TotalCont=0;
DataTable dt = new DataTable();
try
{
//intigration using Basic Aouth with authrization headers
var request = (HttpWebRequest)WebRequest.Create(url);
var username = "SC";
var password = "SK";
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
request.UserAgent = "MyApp 1.0";
var response = (HttpWebResponse)request.GetResponse();
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
JavaScriptSerializer js = new JavaScriptSerializer();
var …Run Code Online (Sandbox Code Playgroud) 我有一个DataTable dt,其中有1200条记录.以下是代码:
DataTable dt = new DataTable();
dt = GetAccCode(c);
Run Code Online (Sandbox Code Playgroud)
现在,使用DataView我想根据1列过滤dt的记录.以下是代码:
EDITED
DataView dv = new DataView(dt);
dv.RowFilter = "AccountDescription LIKE '" + e.Text + "' " ;
dv.RowFilter = "Isnull(AccountDescription,'NULL') <> 'NULL'";
//dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
if (dv.Count > 0)
{
dt = dv.ToTable();
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
C#CODE:
private const int ItemsPerRequest = 50;
private static string GetStatusMessage(int offset, int total)
{
if (total <= 0)
return "No matches";
return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
} …Run Code Online (Sandbox Code Playgroud) 在将其标记为重复之前,我已经看到了许多答案,例如“ 将IEnumerable转换为DataTable”,并试图通过创建扩展方法的方式进行类似的操作。我问我的问题,因为问题可能在其他地方。
从本质上讲,到目前为止,我有相当大的IEnumerable(大约16-17百万个项目),在使用扩展方法尝试转换为数据表之前,我并没有遇到任何问题:
/// <summary>
/// Converts IEnumberable to datatable. Mainly for use when using SQLBulkCopy/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collection"></param>
/// <param name="customColumnOrder">Custom order for columns allows me to make sure that the order of columns will always be the same. Am open for suggestions for better ways to do this</param>
/// <returns></returns>
public static DataTable ToDataTable<T>(this IEnumerable<T> collection, List<Tuple<string, int, int>> customColumnOrder)
{
DataTable dt = new DataTable();
var type = collection.First().GetType();
foreach (var …Run Code Online (Sandbox Code Playgroud) datatable ×10
c# ×7
.net ×3
asp.net ×2
primefaces ×2
charts ×1
dataview ×1
exporter ×1
highcharts ×1
javascript ×1
jquery ×1
jsf ×1
jsf-2 ×1
linq ×1
sql ×1
sql-server ×1
sqlbulkcopy ×1
winforms ×1