小编aba*_*hev的帖子

逐行阅读文本文档的所有内容

我有一个包含多个行的文本文档,其中包含人名,年龄,喜欢的号码和他们喜欢的活动.

例如:

Line 1: Josh 30 100 Likes to play soccer. 
Line 2: May 21 3 Likes to dance.
etc.

我有,我想通过一个展示自己的姓名,年龄,喜欢的数量和活性一个消息框.

我怎么能这样做,我怎么能把他们的数字作为整数呢?谢谢.

对不起,我没有代码,因为我不知道该怎么办,但我正在考虑使用streamreader.

c#

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

存储过程中的"无效列名称"

我编写了一个存储过程来将未来日期(不包括Sat和Sun)插入到永久表中.例程只使用一个临时表.这篇文章的目的不是批评存储过程.虽然,我确信它可以改进.但是,这篇文章的目的是分析为什么存储过程在一组情况下而不是其他情况下调用时会抛出这些错误.

1 - 这是我收到的错误

Msg 207, Level 16, State 1, Procedure MAKE_FUTURE_DATES, Line 25
Invalid column name 'tdate'.
Msg 207, Level 16, State 1, Procedure MAKE_FUTURE_DATES, Line 31
Invalid column name 'wday'.
Run Code Online (Sandbox Code Playgroud)

2 - 这是存储过程

ALTER PROCEDURE [dbo].[MAKE_FUTURE_DATES] (@STARTDATE DATE)
AS
BEGIN
-- We need to populate FUTURE_DATES (table) with forward looking dates (week days only) 
-- We do not consider/exclude holidays here. We just exclude Sat/Suns

-- Temp table to hold the dates and days of the week
    CREATE …
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server stored-procedures sql-server-2008-r2

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

从文件路径中提取文件名之前的文件夹名称

如何提取文件名前面的文件路径的文件夹名称?

例:

declare @a varchar(200)
set @a = '/path/to/category1/filename.txt'
select right(@a, charindex('/', reverse(@a)) - 1)
Run Code Online (Sandbox Code Playgroud)

这将返回filename.txt - 在另一列中,我现在想要获取"category1"文件夹名称.如果路径更改为: set @b = '/path/to/another/folder/category2/filename.txt' 它应提取category2.

sql t-sql sql-server sql-server-2012

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

如何在不添加新变量的情况下将其转换为DateTime?

我是C#的新手.所以我有一个非常简单的问题.我有一个字符串值.如何在不添加新变量的情况下将其转换为DateTime?这是代码:

string start_date = DateTime.Now.ToString("MM.dd.yyyy");
startdate.Text = start_date;

DateTime start_date = Convert.ToDateTime(start_date); 
start_date = start_date.AddDays(1);
startdate.Text = Convert.ToString(start_date);
Run Code Online (Sandbox Code Playgroud)

我想在没有添加变量的情况下将start_date转换为start_date.在Convert.ToDateTime(start_date)命令中,我可以使用startdate.Text而不是start_date ....

c# datetime

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

如果在运行LINQ后没有匹配,变量会保持什么

[WebMethod]
public List<FavoritesTO> getFavorites(string username)
{
    using (FavoritesDataContext db = new FavoritesDataContext ())
    {
        var query = from row in db.Favorites
                    where username == row.username
                    select row.imdbId;
        // here
    }
}
Run Code Online (Sandbox Code Playgroud)

在标记为此处的区域中,查询变量将保留什么,例如,如果我的表中没有与传递给函数的用户名匹配的用户名?

c# linq linq-to-sql webmethod

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

BinarySearch太慢了

怎么可能当我在SortedList上使用.net BinarySearch时,它需要的时间比我在同一个列表上使用我自己的二进制搜索方法要长得多?

使用.net binarysearch:

int ipos = MyList.Keys.ToList().BinarySearch(unSearchFor);

if (ipos >= 0)
{
    // exact target found at position "ipos"
    return MyList[unSearchFor];
}
else
{
    // Exact key not found: 
    // BinarySearch returns negative when the exact target is not found,
    // which is the bitwise complement of the next index in the list larger than the target.
    ipos = ~ipos;
    try
    {
        return MyList.Values[ipos - 1];
    }
    catch
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的二元搜索方法:

int nStart = 0;
int …
Run Code Online (Sandbox Code Playgroud)

.net c# performance binary-search

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

制造虚空动态

我创建了一些动态的图片框,但我不知道如何对点击进行单独操作.

PictureBox[] app=new PictureBox[file.Length];
int i = 0, prev=20;
foreach(string element in file)
{
    app[i] = new PictureBox();
    app[i].BackgroundImage = Image.FromFile(element.Remove(element.Length - 3) + "png");
    app[i].Location = new Point(prev, 85);
    app[i].Size = new Size(100, 100);
    app[i].Name = "test" + i;
    app[i].Click += new EventHandler(run(element, dir));

    this.Controls.Add(app[i]);

    i++; 
    prev += 20;
}

private void run(string element, string dir)
{
      MessageBox.Show(element);
}
Run Code Online (Sandbox Code Playgroud)

那我怎么能这样做呢.请帮忙!谢谢!

c# events dynamic void winforms

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

Windows 服务屏幕捕获不起作用

我创建了一个 Windows 服务,需要捕获桌面屏幕,但结果图像是黑色的。我知道Windows服务需要分配给winsat0/默认桌面。我使用 user32.dll 函数与用户桌面交互,但它不起作用!

我在桌面类中的代码是这样的:

internal bool BeginInteraction()
{
    EndInteraction();
    m_hCurWinsta = User32DLL.GetProcessWindowStation();
    if (m_hCurWinsta == IntPtr.Zero)
        return false;

    m_hCurDesktop = User32DLL.GetDesktopWindow();
    if (m_hCurDesktop == IntPtr.Zero)
        return false;

    m_hWinsta = User32DLL.OpenWindowStation("Winsta0", false,
        WindowStationAccessRight.WINSTA_ACCESSCLIPBOARD |
        WindowStationAccessRight.WINSTA_ACCESSGLOBALATOMS |
        WindowStationAccessRight.WINSTA_CREATEDESKTOP |
        WindowStationAccessRight.WINSTA_ENUMDESKTOPS |
        WindowStationAccessRight.WINSTA_ENUMERATE |
        WindowStationAccessRight.WINSTA_EXITWINDOWS |
        WindowStationAccessRight.WINSTA_READATTRIBUTES |
        WindowStationAccessRight.WINSTA_READSCREEN |
        WindowStationAccessRight.WINSTA_WRITEATTRIBUTES
        );
    if (m_hWinsta == IntPtr.Zero)
        return false;

    User32DLL.SetProcessWindowStation(m_hWinsta);

    m_hDesk = User32DLL.OpenDesktop("default", OpenDesktopFlag.DF_NONE, false,
        DesktopAccessRight.DESKTOP_CREATEMENU |
        DesktopAccessRight.DESKTOP_CREATEWINDOW |
        DesktopAccessRight.DESKTOP_ENUMERATE |
        DesktopAccessRight.DESKTOP_HOOKCONTROL |
        DesktopAccessRight.DESKTOP_JOURNALPLAYBACK |
        DesktopAccessRight.DESKTOP_JOURNALRECORD |
        DesktopAccessRight.DESKTOP_READOBJECTS |
        DesktopAccessRight.DESKTOP_SWITCHDESKTOP |
        DesktopAccessRight.DESKTOP_WRITEOBJECTS …
Run Code Online (Sandbox Code Playgroud)

c# windows winapi windows-services

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

删除前显示提醒

我有一个动作链接将ID传递给我的控制器中的Deletemethod.

@Html.ActionLink("Delete", "DeleteContent", new { xid = item.Id }) 
Run Code Online (Sandbox Code Playgroud)

我想要点击链接时触发的"确认操作"-alert.让我们说警报有两个选项,"删除"和"取消".

如果用户点击取消我不希望该方法执行.

有关如何实现这一目标的任何提示?

javascript c# asp.net-mvc

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

如何摆脱编译错误:C#使用未分配的局部变量?

我有一些问题,为什么C#不喜欢这coordinates[j]部分以及我能做些什么.

string[] lines = System.IO.File.ReadAllLines(@"C:\Users\sp\Dropbox\ProjectEuler\102\p102_triangles.txt");
string[] coordinates_str;
double[] coordinates; //Contains the coordinates for each line A1(x,y), A2(x,y), A3(x,y)
long ln = lines.Length;
Console.WriteLine("Length: " + ln.ToString());
for (int i = 0; i < ln; i++)
{
    Console.Write(i);
    Console.Write(lines[i]);
    coordinates_str = lines[i].Split(',');
    for (int j = 0; j < 6; j++)
    {
        coordinates[j] = Convert.ToDouble(coordinates_str[j]);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# compiler-errors unassigned-variable

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