我有一个数据表,其中包含3列Column1, Column2和Column3数据.我可以使用以下代码清除单列值.
dtTable.Rows.OfType<DataRow>().
ToList().
ForEach(r => r["Column1"] = DBNull.Value);
Run Code Online (Sandbox Code Playgroud)
我需要清除同一数据表的两列; 有没有方法在同一行代码中指定两个列名?
我有一个会在其中存储DataTable的会话.它可能不是最好的主意,但它对我来说非常有效.我的问题是,我知道如果Session为空或者为null,如何检查Session.但我不知道如果它有数据表,如何检查Session
这是我的代码,用于检查会话中是否包含字符串
if (!string.IsNullOrEmpty(Session["stok_kodu"] as string))
Run Code Online (Sandbox Code Playgroud)
不幸的是,DataTable类没有像下面那样的"IsNullOrEmpty"函数.
// this is wrong
if (!DataTable.IsNullOrEmpty(Session["stok_kodu"] as DataTable))
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我使用以下方法从数据表中获取总数
string total = dt.AsEnumerable().Sum(x => x.Field<decimal>("col1")).ToString();
Run Code Online (Sandbox Code Playgroud)
当col1的所有值都是数字时,这可以正常工作.
我的问题是 - 让我们考虑col1的任何一个值是否为字符串或null或除数字以外的任何其他值,上面的代码显然会抛出错误.
有没有办法检查值是否为数字,如果值不是数字,则使用"0".
我试过了 -
string total = dt.AsEnumerable().Sum(x => x.Field<decimal>("col1") is int ? x.Field<decimal>("col1") : 0).ToString();
Run Code Online (Sandbox Code Playgroud)
但不确定它是否正确.
请帮忙
我正在尝试使用PrimeFaces ShowCase中的 Frozen Column .
但我无法设置第一个冷冻柱的宽度,这实在太宽了.

有人可以告诉我如何解决它?
XHTML:
<p:dataTable var="car" value="#{dtScrollView.cars}"
scrollable="true" scrollHeight="150"
scrollWidth="300" frozenColumns="1">
<p:column headerText="Id" footerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year" footerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
我正在使用PrimeFaces 5.0.
我通过运行存储过程填充数据集,并从数据集中填充数据表.
DataSet RawDataSet = DataAccessHelper.RunProcedure("storedprocedureName");
//this will just return the dataset by running the procedure
DataTable RankTable = RawDataSet.Tables[0];
Run Code Online (Sandbox Code Playgroud)
Datatable具有以下值:
Vicky Login 6/24/2014
Vicky Login 6/25/2014
Arun Game 6/26/2014
Arun Login 6/27/2014
Kumar Login 6/28/2014
Kumar Game 6/29/2014
Arun Login 6/30/2014
Arun Login 7/1/2014
Kumar Game 7/2/2014
Vicky Login 7/3/2014
Arun Login 7/4/2014
Arun Game 7/5/2014
Run Code Online (Sandbox Code Playgroud)
我想解析这个dataTable并获得每个人做了多少次动作,即每行重复多少次:
Vicky Login 3
Arun Game 2
Arun Login 4
Kumar Login 1
Kumar Game 2
Run Code Online (Sandbox Code Playgroud)
我是C#的新手.这可以使用SQL中的count(*)来完成,但我需要使用C#来完成此操作.如果有任何方法可以实现这一点,请告诉我.
我已搜索过SO,但所有帖子都与删除重复项/找到重复项有关,但这并不能解决我的目的.
我使用的数据表如下:
$('#resources_table').dataTable({
"processing": true,
"serverSide": true,
"columns": [
{ "data": "id" },
{ "data": "column1" },
{ "data": "column2" }
],
"ajax": "/resource",
"error": function(reason) {
console.log("error encountered ! ");
// process reason here to know the type of the error
// and then take appropriate action
}
});
Run Code Online (Sandbox Code Playgroud)
不知何故,我无法捕获从服务器返回的错误.如何访问reason和处理error服务器端处理基于ajax的数据表?
PS:我使用的是最新的dataTable版本: DataTables 1.10.1
我有一个RoleStatus枚举,它作为Role实体的属性映射到DB中的整数(但该部分是无关紧要的).我想提出一个List<Role>在<p:dataTable>其中一列应该有一个<h:selectOneMenu>对RoleStatus的财产Role实体.如何使用或不使用OmniFaces实现此功能?
这是枚举:
public enum RoleStatus {
ACTIVE(1, "Active"),
DISABLE(2, "Disable");
private final int intStatus;
private final String status;
private RoleStatus(int intStatus, String status) {
this.intStatus = intStatus;
this.status = status;
}
public int getIntStatus() {
return status;
}
public String getStatus() {
return status;
}
}
Run Code Online (Sandbox Code Playgroud)
这是支持bean:
@ManagedBean
@ViewScoped
public class RoleController {
private List<Role> roles;
@ManagedProperty("#{roleService}")
private IRoleService roleService;
@PostConstruct
public …Run Code Online (Sandbox Code Playgroud) 我使用'jquery-datatables-rails','〜> 2.1.10.0.2'和ajax-datatables-rails.我已经成功地在我的项目中实现了两个用例,但在第三个我遇到了这个问题.
我的视图文件是:
<div class="container">
<div class="row">
<h3>My Books</h3>
<div class="column">
<div class="bs-docs-section">
<div class="col-lg-12">
<div class="bs-component">
<div class="table-responsive">
<table id="dataentriesDatatable" class="table table-striped table-hover table-bordered" data-source="<%= dataentries_path(format: :json) %>">
<thead class="theaderGray">
<tr>
<th>Edit Book</th>
<th>Name</th>
<th>Subject</th>
<th>Standard</th>
<th>Book Entry Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的datatable js文件是:
var dtable = $('#dataentriesDatatable').dataTable({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"processing": true,
"serverSide": true,
"deferRender": true,
"bServerSide": true,
"ajax": $('#dataentriesDatatable').data('source'),
//"ajax": "../data/userarrays.txt",
"aoColumns": [
{ "bSortable": false },
{ "bSortable": …Run Code Online (Sandbox Code Playgroud) 我有一个DataTable并希望保留过滤器.我可以保存过滤器值并通过调用数据表将它们放回去.我把滤镜值放回渲染上.现在我希望过滤表格.
是的,我想调用一个服务并从中获取所有数据然后我想过滤表中的值保留在过滤器字段中.
表格渲染后,我找不到解决方案来启动过滤. 重写PrimeFaces方法的解决方案不能在我的情况下使用.
更新:如果可以使用Java或xhtml解决问题,我正在尝试不使用其他js
我正在使用Primefaces 3.5
你有什么想法?
谢谢!:)
我正在尝试使用LINQin,DataTable而我使用了Ntier作为解决方案,但是当我尝试使用LINQin 时却DataTable给了我一个错误:对不起,我的英语
Error 1 Cannot convert lambda expression to type 'string' because it is not a delegate type c:\users\ba-ojt\documents\visual studio 2010\Projects\GoActiveDirectory\PresentationTier\Default.aspx.cs 21 25 PresentationTier
Run Code Online (Sandbox Code Playgroud)
我该如何解决它以及如何使其成为lambda表达式?
我的代码:
protected void Page_Load(object sender, EventArgs e)
{
DataServiceReference.Service1Client newService = new DataServiceReference.Service1Client();
DataTable dt = newService.GetAccounts();
var query = from data in dt
select data;//Error Here
Repeater1.DataSource = query;
Repeater1.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
我的参考:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data; …Run Code Online (Sandbox Code Playgroud)