假设我有一个来自表的列值的列表,如何删除空字符串和重复值.请参阅以下代码:
List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList();
Run Code Online (Sandbox Code Playgroud)
这就是我刚刚编写的内容,但是Amiram的代码更优雅,所以我会选择答案就是这样做:
DataTable dtReportsList = someclass.GetReportsList();
if (dtReportsList.Rows.Count > 0)
{
List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList();
dtList.RemoveAll(x=>x == "");
dtList = dtList.Distinct().ToList();
rcboModule.DataSource = dtList;
rcboModule.DataBind();
rcboModule.Items.Insert(0, new RadComboBoxItem("All", "All"));
}
Run Code Online (Sandbox Code Playgroud) 如何替换jQuery中的任何字符串?
假设我有一个字符串"-9o0-9909",我想用另一个字符串替换它.
如何DateTime从行中获取C#的值,当前代码给出错误,任何帮助都表示赞赏,数据来自进度数据库:
foreach (DataRow r in ds.Tables[0].Rows)
{
string prodCode = r["PRD-CDE"].ToString();
statCode = r["STAT"].ToString();
DateTime firstIssueDate = (DateTime)(r["FISS"]);
DateTime endIssueDate = (DateTime)(r["EISS"]);
if(endIssueDate > DateTime.Now)
{ /*do some thing...*/}
else {/*user invalid...*/}
}
Run Code Online (Sandbox Code Playgroud)
获取日期转换和解析有两种方法,谢谢大家的帮助
最终工作代码段:
foreach (DataRow r in ds.Tables[0].Rows)
{
string prodCode = r["PRD-CDE"].ToString(),statCode = r["STAT"].ToString();
// r.<DateTime?>("FISS");
if (r["FISS"] != DBNull.Value)
{
DateTime firstIssueDate = Convert.ToDateTime(r["FISS"]);
if (r["EISS"] != DBNull.Value)
{
DateTime endIssueDate = DateTime.Parse(r["EISS"].ToString());
if (endIssueDate > DateTime.Now)
{
Run Code Online (Sandbox Code Playgroud) 我遇到了这个查询的问题,它引发了一个错误.
var TotalToDatePayable = ( from ori in db.GetAll<WMPORI>()
where ori.CTMSysID == ctmSysId
select ori.ExB4Taxes).Sum();
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码来自另一个类似的问题,但这并没有解决我的问题:
var TotalToDatePayable = (Decimal?)( from ori in db.GetAll<WMPORI>()
where ori.CTMSysID == ctmSysId
select ori.ExB4Taxes).Sum()) ?? 0;
Run Code Online (Sandbox Code Playgroud) 我有一个数据表,我想在这里删除一行是我的代码它给我一个例外
foreach (DataRow row in dt1.Rows)
{
if ((row["Name"] == "Select a Lookbook") || (row["Name"] == "Create a new Lookbook"))
{
row.Delete();
dt1.AcceptChanges();
}
}
Run Code Online (Sandbox Code Playgroud)
我甚至尝试在if语句之外,并且在forloop之外仍然会抛出错误任何想法如何实现此任务这是我获得的异常:
Collection was modified; enumeration operation might not execute.
Run Code Online (Sandbox Code Playgroud)
最终工作守则:
foreach (DataRow row in dt1.Select())
{
if ((row["Name"] == "Select a Lookbook") || (row["Name"] == "Create a new Lookbook"))
{
row.Delete();
}
}
Run Code Online (Sandbox Code Playgroud) 如何在说出2或3分钟之后查看以下代码:
class Program
{
static void Main(string[] args)
{
try
{
//declare new process and name it p1
Process p1 = Process.Start("iexplore", "http://www.google.com");
//get starting time of process
DateTime startingTime = p1.StartTime;
Console.WriteLine(startingTime);
//add a minute to startingTime
DateTime endTime = startingTime.AddMinutes(1);
//I don't know how to kill process after certain time
//code below don't work, How Do I kill this process after a minute or 2
p1.Kill(startingTime.AddMinutes(2));
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Problem with Process:{0}", ex.Message);
}
} …Run Code Online (Sandbox Code Playgroud) 如何检索数据集中的布尔值,我使用的是 Visual Studio 2003,我正在尝试以下操作,但它不起作用:
//if product inactive, don't display, and redirect to main page
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].Equals(0)))
Run Code Online (Sandbox Code Playgroud)
我什至尝试过,但没有工作:
if((dbDataSet.Tables["productGeneral"].Rows[0]["Active"].toString() == false)
Run Code Online (Sandbox Code Playgroud)
列名称为 ["active"],列中的值为 True 或 False,使用 sql server 2000
请帮忙
我有一个arraylist,其中包含不同类型的值,第一个值 - > 字符串,第二个值 - > datetime,第三个值 - > 布尔值和第四个值是int,我如何找到它们的类型并相应地分配这些值,任何感谢帮助:)
这是我的代码:
foreach (object obj in lstTop)
{
if(obj.GetType() == string)
{do this...)
else if(obj.GetType() == DateTime)
{do this....}
else if(obj.GetType() == bool)
{do this....}
else if(obj.GetType() == Int)
{do this....}
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家,我的最终守则:
string Subscription = "";
DateTime issueFirst;
DateTime issueEnd;
foreach (object obj in lstTop)
{
///Type t = obj.GetType();
if (obj is string)
Subscription += obj + ",";
else if (obj …Run Code Online (Sandbox Code Playgroud) 何我要在数据集中向列中添加随机分钟,这是我的代码:
protected void btnUpdateTable_Click(object sender, EventArgs e)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
///check if column[logout] is null or empty, fill it
if(dr.IsNull("logout_time"))
{
///get the login colum datetime
/// add random datetime to it
if (!dr.IsNull("login_time"))
{
DateTime dt = Convert.ToDateTime(dr["login_time"]);
dt = dt.AddMinutes(?);/// "?"<--here I want to add random minutes
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢.
谢谢大家的帮助,这是我的最终代码片段:
foreach (DataRow dr in ds.Tables[0].Rows)
{
///check if column[logout] is null or empty, fill it
if(dr.IsNull("logout_time"))
{
///get the login colum datetime …Run Code Online (Sandbox Code Playgroud) 我正在处理的网站有添加到购物车的链接我想更改该链接指向不同的页面我如何在jquery中实现这一点.
$(document).ready(function() {
//alert('Welcome to StarTrackr! Now no longer under police …');
$("a[href='http://www.somesite.com/scAddItem.aspx?action=add&BJID=421&extra=type,journalIssue,volume,2,issue,<web::ISSUE>,npus,$99.00,npcdn,$99.00']").attr('href', 'http://www.live.com/');
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试从这里得到这个想法 如何使用jQuery更改超链接的href, 但它不适合我任何帮助表示赞赏.
我无法通过抛出不正确格式的异常来将字符串转换为日期:
这是patterens:
DD-MM-YYYY
MM-DD-YYYY
YYYY-DD-MM
YYYY-MM-DD
YYYYDDMM
YYYYMMDD
Run Code Online (Sandbox Code Playgroud)
格式来自下拉列表,这是我尝试不同的方法,但仍然抛出异常:
strCurrentFormat = rcboDateFormat.SelectedValue.ToString();
DateTime db = DateTime.ParseExact(strOldDate, "DD-MM-YYYY", CultureInfo.InvariantCulture);
//DateTime loadedDate = DateTime.ParseExact(strOldDate, strCurrentFormat, null);
Run Code Online (Sandbox Code Playgroud)
我之前已经解决了这个问题,通过取弦,拆分它们并将年,月和日移动到适当的格式,但这需要很长时间,如果有人知道更简单的方法,那将是一个巨大的帮助.
我有一个查询字符串,看起来像这样:
"somename1 = 123&查询字符串=占位符%3dNothing%26anotherid%3dsomevalue&somename = someValue中"
但我希望查询字符串类似于下面的查询字符串,并用更新的查询字符串替换整个查询字符串有没有任何方法可以在没有重定向的情况下执行此操作?
"somename1 = somevalue1&占位符=无&somename2 = somevalue2&somename3 = somevalue3"
基本上需要删除:"QueryString =",空字符串"%3d","&""%26"带"="
到目前为止,我所做的是:
string strQueryString = Request.QueryString.ToString();
if (strQueryString.Contains("QueryString="))
{
strQueryString = strQueryString.Replace("QueryString=", "");
if (strQueryString.Contains("%26")) strQueryString = strQueryString.Replace("%26", "&");
if (strQueryString.Contains("%3d")) strQueryString = strQueryString.Replace("%3d", "=");
string x = strQueryString;
}
Run Code Online (Sandbox Code Playgroud)
和:
// reflect to readonly property
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
if (this.Request.QueryString.ToString().Contains("QueryString="))
{
this.Request.QueryString.ToString().Replace("QueryString=", "");
if (this.Request.QueryString.ToString().Contains("%26")) this.Request.QueryString.ToString().Replace("%26", "&");
if (this.Request.QueryString.ToString().Contains("%3d")) this.Request.QueryString.ToString().Replace("%3d", "=");
string x …Run Code Online (Sandbox Code Playgroud)