小编Chr*_*son的帖子

C#int32 literal只能以long数据类型存储

我准备一个非常棘手的c#考试,这个问题突然出现了.我有以下代码:

 uint zzz = -12u;
Run Code Online (Sandbox Code Playgroud)

-12u被识别为System.Uint32文字,但它只能存储在类型的变量中long.这是为什么 ?

c# literals variable-assignment unsigned-integer

5
推荐指数
1
解决办法
354
查看次数

SqlParameter已经包含在另一个SqlParameterCollection中 - command.Parameters.Clear()不起作用

我在这里绝望了.我无法弄清楚为什么会发生这种异常.我搜索并阅读了这个问题,似乎每个人都设法使用command.Parameters.Clear()来解决它,但这对我不起作用.这是我的代码:

    public class ProductsDataAccess : Connection 
{
    public static SqlParameter[] createParams(Products prod)
    {
        SqlParameter idParam = new SqlParameter("@id", prod.prodID);
        idParam.SqlDbType = System.Data.SqlDbType.VarChar;
        idParam.Size = 45;
        idParam.IsNullable = false;
        idParam.Direction = ParameterDirection.Input;

        SqlParameter nameParam = new SqlParameter("@name", prod.prodName);
        nameParam.SqlDbType = System.Data.SqlDbType.VarChar;
        nameParam.Size = 45;
        nameParam.IsNullable = false;
        nameParam.Direction = ParameterDirection.Input;

        SqlParameter demandParam = new SqlParameter("@demand", prod.demand);
        demandParam.SqlDbType = System.Data.SqlDbType.Int;
        demandParam.IsNullable = false;
        demandParam.Direction = ParameterDirection.Input;

        SqlParameter demandLTParam = new SqlParameter("@demandLT", prod.demandLT);
        demandLTParam.SqlDbType = System.Data.SqlDbType.Int;
        demandLTParam.IsNullable = false;
        demandLTParam.Direction = ParameterDirection.Input;

        SqlParameter …
Run Code Online (Sandbox Code Playgroud)

.net c# sql-server ado.net exception

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

是否有其他方法可以设置长定时器间隔

我正在制作一个程序,必须每30或60分钟检查一次数据库,并在Windows窗体界面中显示结果(如果有的话).当然,在执行数据库检查时,from提供访问的其他功能仍然可用.为此,我使用的是System.Timers.Timer,它在与UI不同的线程上执行一个方法(如果使用这种方法有问题,请随时评论它).我写了一个小而简单的程序,以测试热门的工作,只是注意到我不能真正设置Interval超过1分钟(我需要30分钟到一个小时).我想出了这个解决方案:

public partial class Form1 : Form
{

    int s = 2;

    int counter = 1; //minutes counter

    System.Timers.Timer t;

    public Form1()
    {
        InitializeComponent();

        t = new System.Timers.Timer();
        t.Elapsed += timerElapsed;
        t.Interval = 60000;
        t.Start();
        listBox1.Items.Add(DateTime.Now.ToString());
    }


    //doing stuff on a worker thread
    public void timerElapsed(object sender, EventArgs e)
    {
        //check of 30 minutes have passed
        if (counter < 30)
        {
            //increment counter and leave method
            counter++;
            return;
        }
        else
        {
            //do the stuff
            s++;
            string result = s + …
Run Code Online (Sandbox Code Playgroud)

.net c# timer intervals

-1
推荐指数
1
解决办法
9712
查看次数