我有一个50行的数据,并有一个ID列.我试图得到一个只包含ID的数组:
string [] IDs = (from row in DataTable.Rows
select row["ID"].toString()).ToArray();
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点.我总是收到错误"无法找到他执行查询...."
我不能在我的数据表中设置任何约束,如果我合并两个数据表dt1.Merge(dt2);它显示错误这样Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.默认情况下我在可视化器中查看它显示约束数为2.如何从数据表中删除约束并解决此错误?
我有一个像这样结构的DataTable:
用户名| 价钱
"杰克".01
"杰克".02
"玛丽".03
"玛丽".04
如何在DataTable上使用LINQ返回MAX PRICE FOR JACK(例如:.02)?
设置表的代码(可以忽略).
DataTable tbl = new DataTable();
tbl.Columns.Add("username");
tbl.Columns["username"].DataType = typeof(string);
tbl.Columns.Add("price");
tbl.Columns["price"].DataType = typeof(double);
DataRow r = tbl.NewRow();
r["username"] = "jack"; r["price"] = .01;
tbl.Rows.Add(r);
r = tbl.NewRow();
r["username"] = "jack"; r["price"] = .02;
tbl.Rows.Add(r);
r = tbl.NewRow();
r["username"] = "mary"; r["price"] = .03;
tbl.Rows.Add(r);
r = tbl.NewRow();
r["username"] = "mary"; r["price"] = .04;
tbl.Rows.Add(r);
Run Code Online (Sandbox Code Playgroud)
这是我被卡住的地方.想以最高价格为杰克退回一行(例如:".02").
var result =
from row in tbl.AsEnumerable()
where (string) row["username"] == "jack"
group …Run Code Online (Sandbox Code Playgroud) 我编写了下面的代码片段,它读取给定的xml文件并将内容写入数据表.请不要建议使用LinqToXml,因为这是一个遗留应用程序.
// create the DataTable that will hold the data
DataTable table = new DataTable("ListOfPersonsWithInfo");
// open the file using a Stream
using (Stream stream = new FileStream(fileNameWithAbsolutePath, FileMode.Open, FileAccess.Read))
{
// create the table with the appropriate column names
table.Columns.Add("Name", typeof(String));
table.Columns.Add("ImagePath", typeof(String));
table.Columns.Add("Address", typeof(String));
// use ReadXml to read the XML stream
table.ReadXml(stream);
// tried with this overload-option as well but didnt help
//table.ReadXml(fileNameWithAbsolutePath);
// return the results
return table;
}
Run Code Online (Sandbox Code Playgroud)
但是返回的表包含ZERO行...... !!! 其中实际的xml文件有'3行',结构如下(任何IDEA这里出了什么问题?):
<?xml version="1.0" encoding="utf-8"?>
<Details> …Run Code Online (Sandbox Code Playgroud) 嗨,我正在我的API上生成一个JSON,我试图在我的Web应用程序中使用代码隐藏C#,但我不能很好地反序列化.
我的JSON有一个带有JSON数组的对象,并且数组中的元素是动态的,所以我不能用这些项创建一个固定的类,因为我的JSON可以有N个项目.
{
"MAINOBJET": [{
"ITEM1": "23800",
"ITEM2": "Dahl; Police",
"ITEM3": "test@test.net"
},
{
"ITEM1": "23802",
"ITEM2": "Steve ; Police",
"ITEM3": "test2@test.net"
}]
}
Run Code Online (Sandbox Code Playgroud)
那么如何将其反序列化为DataTable,列表或字典呢?谢谢
我不知道如何重置primefaces数据表,然后重新加载数据.
有任何想法吗?

一旦我点击"老师"或"众议院领导团队",我发送一个ajax调用,然后我想完全重置数据表,然后重新加载数据.
以下是与两个面板相关的部分:
#{msgs.typeOfLeaderPunishment}
<f:ajax event="valueChange" listener="#{detentionForm.updateData()}" execute="typeOfLeader" render="typeOfPunishment studentTable">
<p:selectOneMenu id="typeOfLeader" value="#{detentionForm.typeOfLeaderSelectedID}" style="width:400px" panelStyle="width:150px" effect="fade">
<f:selectItems value="#{detentionForm.teacherTypes}" var="type" itemLabel="#{type.label}" itemValue="#{type.value}" />
</p:selectOneMenu>
</f:ajax>
Run Code Online (Sandbox Code Playgroud)
这部分涉及选择"众议院领导团队"或"老师",然后将触发更新数据表的ajax调用.
<p:dataTable id="studentTable" var="student" value="#{detentionForm.students}" paginator="true" rows="10" selection="#{detentionForm.studentSelected}" filterDelay="200" filteredValue="#{detentionForm.filteredStudents}" binding="#{detentionForm.studentTable}">
<f:facet name="header">
Students:
</f:facet>
<p:column id="prefName" headerText="Preferred Name" sortBy="=#{student.prefName}" filterBy="#{student.prefName}" filterMatchMode="contains">
#{student.prefName}
</p:column>
<p:column id="lastName" headerText="Last Name" sortBy="#{student.lastName}" filterBy="#{student.lastName}" filterMatchMode="contains">
#{student.lastName}
</p:column>
<p:column id="house" headerText="House" sortBy="#{student.house}">
#{student.house}
</p:column>
<p:column id="code" headerText="Student Code" sortBy="#{student.studentCode}" >
#{student.studentCode}
</p:column>
<p:column id="gender" headerText="Gender" sortBy="#{student.gender}">
#{student.gender}
</p:column>
<p:column id="formName" …Run Code Online (Sandbox Code Playgroud) 我的xhtml中有以下内容
<h:form id="clientTableForm" prependId="false">
<p:dataTable id="clientTable" widgetVar="clientTableVar"
var="client" value="#{resendEmailController.lazyDataModel}"
paginator="true" rows="15"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
rowsPerPageTemplate="5,10,15,20,25,50,75,100"
paginatorPosition="bottom" pageLinks="5" lazy="true"
sortBy="#{client.cclnCode}" sortOrder="ascending"
selection="#{resendEmailController.selectedClient}"
selectionMode="single" filterDelay="500" scrollable="true"
scrollHeight="380">
<p:ajax event="rowSelect"
listener="#{resendEmailController.changeClient}"
update="_accountTableForm_accountTable" />
<p:column id="cclnCodeColumn" headerText="Client Code"
style="width:25%;" sortBy="#{client.cclnCode}"
filterBy="#{client.cclnCode}" filterMaxLength="10">
<h:outputText value="#{client.cclnCode}"
converter="#{trimStringConverter}" />
</p:column>
<p:column id="cclnNamenColumn" headerText="Client Name"
style="width:75%" sortBy="#{client.cclnName}"
filterBy="#{client.cclnName}" filterMaxLength="50">
<h:outputText value="#{client.cclnName}"
converter="#{trimStringConverter}" />
</p:column>
</p:dataTable>
</h:form>
</p:layoutUnit>
<script type="text/javascript">
$(document).ready(function()
{
autoSelectClient();
});
function autoSelectClient()
{
if (clientTableVar.isEmpty() == false)
{
clientTableVar.selectRow(1, false);
} …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
//myDataTable has the following collumns: UserName, Birthday and email.
string name = "eric!";
string expression = "UserName = " + name;
DataRow[] result = myDataTable.Select(expression);
Run Code Online (Sandbox Code Playgroud)
我想选择所有名称为“ eric!”的行。
“!” 给我以下错误:
无法解释令牌“!”。
如何选择带有此类标记的所有行?
(由于从.sql文件中提取了用户名,因此我确实需要在表达式中加上“!”)
如何从c#中的DataTable获取特定列值
我的代码C#有问题.
我需要从DataTable中读取特定的列值.
我尝试使用此解决方案但没有成功,因为输出是在查询(文件)中选择的列的名称,而不是字段数据库的值.
我非常感谢您在解决这个问题时能给我的任何帮助.
这是我的代码:
public DataTable GridViewBind()
{
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
sql1 = " SELECT FILE FROM tbl_A WHERE Id = 1; ";
using (OdbcDataAdapter command =
new OdbcDataAdapter(sql1, cn))
{
try
{
cn.Open();
dset = new DataSet();
dset.Clear();
command.Fill(dset);
DataTable dt = dset.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
Response.Write(dt.Columns[0].ToString());
return dt;
}
catch (Exception ex)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
if (command != null) …Run Code Online (Sandbox Code Playgroud) 我有一个在$( document ).ready函数中创建的表.我也在使用jQuery DataTables插件.出于某种原因,当页面加载时,表格加载但第一行显示"表中没有数据".
HTML
<head>
<link rel="stylesheet" type="text/css" href="/path/to/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="/path/to/js/jquery.dataTables.js"></script>
Run Code Online (Sandbox Code Playgroud)
</head>
<div class="col-sm-12" id="ovs-sum">
<table class="table table-striped" id="summary-table">
<thead>
<tr>
<th>Order</th>
<th>Planner</th>
<th>Vendor</th>
<th>SKU</th>
<th>Description</th>
<th>Quantity</th>
<th>PO Date</th>
<th>PO Tracking</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
JS/jQuery(scripts.js)
$ ( document ).ready(function() {
$.ajax({
type: 'GET',
url: 'models/summary.php',
mimeType: 'json',
success: function(data) {
$.each(data, function(i, data) {
var body = "<tr>";
body += "<td>" + data.name + "</td>";
body += "<td>" + data.address + "</td>"; …Run Code Online (Sandbox Code Playgroud) datatable ×10
c# ×6
jsf ×2
linq ×2
primefaces ×2
.net ×1
ajax ×1
arrays ×1
collections ×1
constraints ×1
dictionary ×1
events ×1
expression ×1
html ×1
javascript ×1
jquery ×1
json ×1
reset ×1
syntax-error ×1
token ×1
xml ×1