小编Xar*_*uth的帖子

使用linq vb.net从数据表中检索不同的值

我正在尝试从数据表中的特定列检索所有不同的值。数据表中的列名称为“计数”。我有2240行,“计数”列中有6个不同的值。问题是,当我执行以下代码时,它给了我行数而不是6个不同的值。

Dim counts = (From row In loadedData
Select row.Item("Count")).Distinct()
For Each i In counts
    MsgBox(i)
Next
Run Code Online (Sandbox Code Playgroud)

如何修改此值以检索6个不同的值,而不是给我总的行数?

linq vb.net datatable

1
推荐指数
2
解决办法
3万
查看次数

asp.net中的一个C#sql注入方法到多个网站

我有多个网站,其中一些从POST获取参数,一些有JQuery AJAX处理程序,一些在查询字符串,一些在onclick asp:Button或ImageButton ..

我想制作一个方法,我可以放在我的所有网站,这将处理所有.我做了这个方法:

private void Si()
{     
    foreach (String key in Request.Params)
    {
        string temp = Request[key];

        string[] array_split_item = new string[] { "–", ";", "/*", "*/", "@@", "char", "nchar", "varchar", "nvarchar", "alter", "begin", "cast", "create", "cursor", "declare", "delete", "drop", "end", "exec", "execute", "fetch", "insert", "kill", "open", "select", "sys", "sysobjects", "syscolumns", "table", "update", "<script", "<//script>", "‘" };


        foreach (string strItem in array_split_item)
        {
            temp = temp.ToLower().Replace(strItem.ToLower(), "");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但有2个问题:

  1. 这是制作这种方法的最佳方法吗?

  2. 是否有可能知道某人是否已被"抓住"此方法试图注入某些东西?如果是这样,怎么样?

谢谢!

c# asp.net security

0
推荐指数
1
解决办法
132
查看次数

扩展方法如何在C#中工作?

我不完全确定如何确定方法是否是扩展方法.我阅读了以下指南:

  1. 该方法必须在静态类中(例如"IntExtensions").

  2. 该方法需要是"公共静态"(例如public static int Half(this int source))

我对扩展方法的问题是:

  1. 我不明白我们是如何知道该方法正在扩展的类.它是this前面的类吗?所以在上面的例子中它将是字符串?
  2. 包含该方法的静态类起什么作用?整个语法似乎很混乱.
  3. 我不能为同一个类下的不同类分组许多不同的扩展方法(这似乎没有意义,因为我只想扩展1个类)例如:

/

public static class IntExtensions 
{
    // method has to be static, first parameter is tagged with the 'this'
    // keyword, the type of the parameter is the type that is extended.
    public static int Half(this int source) 
    {
        return source / 2;
    }

    public static string foo( this string s)
    {
        //some code
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
2
解决办法
229
查看次数

在WPF中设计具有样式的垂直滚动条

这可能很容易做,也可能很困难,但是任何人都可以告诉我如何设计scrollviewer像这样的图像垂直滚动查看器

在设计领域,我对 WPF 还很陌生。我在 Visual studio Blend 2013 中了解了这个设计,并且喜欢这个 UI 的外观和感觉,请建议一种在 xaml 或 UI 后面的代码中为其编码的方法。

这是我的拇指方法

<Style x:Key="ScrollThumbs" TargetType="{x:Type Thumb}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
                <Grid x:Name="Grid">
                    <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Fill="Transparent" />
                    <Border x:Name="Rectangle1" CornerRadius="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto"  Background="LightGray" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="Tag" Value="Horizontal">
                        <Setter TargetName="Rectangle1" Property="Width" Value="Auto" />
                        <Setter TargetName="Rectangle1" Property="Height" Value="7" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

但是如何更改上下箭头。

c# wpf xaml

0
推荐指数
1
解决办法
5674
查看次数

"并非所有代码路径都返回值"C#

您好我目前正在Windows Phone/C#上编写petshop应用程序的婴儿阶段.我在下面的课程中设置了我的通用列表,并且能够使用给定的字段(姓名,年龄,品种和类型)将宠物添加到商店.我相信的问题在于我正在制作一个显示方法(在下面称为Mainpage.xaml.cs的另一个页面中,名为Mainpage.xaml.cs),名为DisplayShop(),我正在阅读3个字符串和一个int,我相信它与我的DisplayShop()方法是一个字符串这一事实有关,虽然我试图通过将age字段转换为Display()方法中的字符串来解决问题,尽管这并没有解决问题.

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink; 
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment_1
{
    public class Shop
    {
        private string name;
        private int age;
        private string breed;
        private string type;

        public Shop(string Name, int Age, string breed, string Type)
        {
            this.Name = name;
            this.Age = age;
            this.breed = breed;
            this.Type = type;
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set …
Run Code Online (Sandbox Code Playgroud)

c# windows xaml

0
推荐指数
1
解决办法
274
查看次数

替换switch语句 - 通过字符串名称获取属性

基本上,我有一个系统,我的datagrid标记已更改为新背景颜色的单元格,为此我在对象中有一个方法,包含这些属性,接收一个字符串,这是要检查的属性的名称,然后是一个switch语句,它接受该字符串来检查正确的属性.

public Color HasChanged(string value)
{
    switch (value)
    {
        case "CILRef":
            if (_localShipment.cilRef != _originalShipment.cilRef)
            {
                return Colors.SkyBlue;
            }
            else
            {
                return Colors.White;
            }
        case "ArrivedAtPortDate":
            if (_localShipment.arrivedAtPortDate != _originalShipment.arrivedAtPortDate)
            {
                return Colors.SkyBlue;
            }
            else
            {
                return Colors.White;
            }
    }
}
Run Code Online (Sandbox Code Playgroud)

为简洁起见,我删除了其余的属性.

现在我有一种唠叨的感觉,有一种更简洁的方法来做这个字符串>属性而不使用switch语句,但我不能在我的生活中找到谷歌的任何东西,很难搜索没有一些关键字继续下去.

我也试图只保存那些已更改的属性,我将任何已更改的属性名称放入一个数组中,然后使用另一个switch语句循环检查该数组,然后保存正确的属性.然而,这对我来说再次显得不整齐.

是否有一个更清晰的解决方案,希望可以处理添加新属性,而无需向switch语句添加新代码.

如果需要,我可以包括执行此检查的其余代码(即数据网格上的WPF绑定,以及使用属性名称作为字符串参数调用检查方法的转换器).

c# wpf switch-statement

0
推荐指数
1
解决办法
259
查看次数

如何让我的文本框只允许1-14号?

这是我到目前为止,但我显然是一个错误.

try
{
    dblNights = Convert.ToDouble(txtNights.Text);

    if (dblNights > 1 && 14)
    {
    }
    else
    {
        string script = "alert(\"Number of Nights Must be between 1 and 14!\");";
        ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);
        txtNights.Focus();
    }
}//End Try

catch
{
    string script = "alert(\"Number of Nights Must be an Integer!\");";
    ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);

    txtNights.Focus();
}//End Catch
Run Code Online (Sandbox Code Playgroud)

如果输入1-14之外的数字,我不太清楚如何显示错误框.其他一切都在起作用,就是这样.我究竟做错了什么?

谢谢.

c# asp.net

0
推荐指数
1
解决办法
112
查看次数

标签 统计

c# ×6

asp.net ×2

wpf ×2

xaml ×2

datatable ×1

linq ×1

security ×1

switch-statement ×1

vb.net ×1

windows ×1