我的gridview上有一个删除按钮.在单击"删除"按钮时,应该从会话中完全删除该行.我目前正在做以下事情:
protected void gvMainLog_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Remove")
{
GridViewRow rowSelect = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int rowindex = rowSelect.RowIndex;
DataSet ds = ((DataSet)Session["old"]);
ds.Tables[0].Rows[rowindex].Delete();
Session["old"] = ds;
gvMainLog.DataSource = Session["old"];
gvMainLog.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
问题是:
ds.Tables[0].Rows[rowindex].Delete();
Run Code Online (Sandbox Code Playgroud)
仅删除该行中的内容.当我查看数据集时,它显示一个空行.
有没有办法可以删除整行,而不显示空行?
我需要一个报告,我希望我的SQL查询重复每一行两次.
示例:
**Table 1**
Id Name
1 Ab
2 Cd
3 Ef
Run Code Online (Sandbox Code Playgroud)
我想编写一个输出以下内容的查询:
1 Ab
1 Ab
2 Cd
2 Cd
3 Ef
3 Ef
Run Code Online (Sandbox Code Playgroud)
有没有办法可以做到?
除了使用之外我什么都想不到 union
Select Id, name from Table1 union select Id, name from Table1
Run Code Online (Sandbox Code Playgroud) 我有一个存储过程返回一个布尔变量:
这是我的C#代码,当我尝试返回一个int变量时工作.但是当我尝试bool时它不起作用.
DbCommand dbCommand = db.GetStoredProcCommand("spGetConfigureAlerts");
object o = db.ExecuteScalar(dbCommand);
bool item = o == null ? 0 : (bool)o;
return item;
Run Code Online (Sandbox Code Playgroud)
我如上所示,但在第三行它说:
Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'bool'
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我有一个复杂的查询,可以连接7个以上的表。加入后,我想过滤查询的结果。
这是我观察到的。
当我执行where子句时
where X.Name != 'xxx'
and XY.Product != 1
Run Code Online (Sandbox Code Playgroud)
我得到了过滤后的结果,但X.Name和XY.Product的所有空值也从我的结果中消失了。我想保留空值。
我也尝试过:
and X.Name != 'xxx'
and XY.Product != 1
Run Code Online (Sandbox Code Playgroud)
我完全删除了where子句,并放入了and,但是我完全看不到这种方法的过滤。
有没有一种方法可以过滤我的结果而不会丢失空值?
我有两个JOIN查询,它们给出一个输出列Id.如何查找Id查询1返回的所有值,但查询2不返回?
select Id from Table1 join Table2;
select Id from Table2 join Table3;
Run Code Online (Sandbox Code Playgroud) var CC = new List<Company>();
Company t1 = new Company();
t1.Comp = "ABC";
t1.Area = "Area1";
t1.Link = "https://www.google.com";
CC.Add(t1);
Company t2 = new Project();
t2.Comp = "DEF";
t2.Area = "Area2";
t2.Link = "https://www.yahoo.com";
CC.Add(t2);
var a = from p in CC where p.Comp == "ABC" && p.Area == "Area1"
select p.Link;
Console.WriteLine(a);
Console.Read();
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我希望将输出视为"www.google.com".
但我所看到的是.
我哪里错了?我怎样才能看到"www.google.com"?
我有以下查询,我想在Percentage包含聚合的表达式上使用where子句:
SELECT Percentage = CONVERT(DECIMAL(10,1),100 - COUNT(some_irrelevant_column))
FROM Product P INNER JOIN Item PD
ON PD.ProductId = P.ProductId
WHERE Percentage < 50;
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误:
列名称'Percentage'无效.
大家好,
我有一个对象列表ArrayList PList.该对象看起来像这样
Product
{
int ProductId,
string ProductDescription,
int StoreId
int supplierid
}
Run Code Online (Sandbox Code Playgroud)
我想将非重复的Products组合添加到另一个数组中
Product[] Parray
Run Code Online (Sandbox Code Playgroud)
例:
ArrayList Plist 具有 :
productid , productdescription, storeid, supplierid
1, "AB", 11 , 123
2, "CD", 24 ,454
1, "AB", 11 ,431
Run Code Online (Sandbox Code Playgroud)
我想要产品[] Parray
productid , productdescription, storeid, supplierid
1, "AB", 11 ,123
2, "CD", 24 , 454
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用哈希表来获取键值对,但在这种情况下我有3个键ProductId,description&storeid
这是我现在的代码:
private Types.Product[] LoadProducts()
{
ArrayList PList = new ArrayList();
// Business Logic , extracting values from xml using xpath
//Loop …Run Code Online (Sandbox Code Playgroud) 我有两个字符串列表:
List<string> lotterynumber;
List<string> lotterywinningnumber;
Run Code Online (Sandbox Code Playgroud)
我想看看 a 是否lotterynumber在lotterywinningnumber.
foreach我现在正在使用循环:
bool b = false;
foreach(string s in lotterynumber)
{
if(lotterywinningnumber.contains(s))
{
b= true;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么办法可以在 Linq 中做到这一点吗?