Sipo Blog

宁静致远

用Linq查询/排序/过滤DATATABLE

LINQ不能直接查询DataTable,这样就可以了。


            DataTable dt = new DataTable();
            dt.Columns.Add("colname1");
            dt.Columns.Add("http://www.dc9.cn/");
            dt.Columns.Add("colname3");
 var selectedRows = from r in dt.AsEnumerable() orderby r.Field<string>("colname3") descending select r;

.net 3.5下用Lambda简化跨线程访问窗体控件,避免繁复的delegate,Invoke

1,错误的代码是:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string blog="http://www.dc9.cn/";


        private void Form1_Load(object sender, EventArgs e)
        {
            new System.Threading.Thread(ShowTime).Start();
        }

        private void ShowTime()
        {
            textBox1.Text = DateTime.Now.ToString();
        }
    }
}


会看到Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.的错误

2,增加一个Public static 类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication5
{
    public static class ControlExtention
    {
        public delegate void InvokeHandler();

        public static void SafeInvoke(this Control control, InvokeHandler handler)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(handler);
            }
            else
            {
                handler();
            }
        }
    } 
}


3,build

4,这样写就好啦

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string s="http://www.dc9.cn/";

        private void Form1_Load(object sender, EventArgs e)
        {
            new System.Threading.Thread(ShowTime).Start();
        }

        private void ShowTime()
        {
            this.SafeInvoke(() => {
                textBox1.Text = DateTime.Now.ToString();            
            });
        }
    }
}

FLASH CS3/CS4 使用外部AS文件的Hello World

1,建立一个FLA

2,建立一个AS

3,内容如下

package {
  
  import flash.display.*;

  public class Main extends MovieClip  {

    // Constants:
    // Public Properties:
    // Private Properties:

    // Initialization:
    public function Main() {

      trace("hola");

    }

    // Public Methods:
    // Protected Methods:
  }

}


4,在FLA的属性里面的Document Class里面写上 Main

5,就这样,你就可以不在时间线上写AS了。

与天同泣,重生抑或死刑。

北京又下雨了,只是这次的雨格外的落寞。
21日本是个重生的红火日子,然而却由一场雨浇息了,空气里弥漫着仿佛死一般的嘈杂。
想想也罢,举国不顺,又有什么好悲哀的。连蒙牛伊利都没人问津了。
借用一句歌词好了:
唉懒得去管顺其自然
天空为你我而蓝
烦脑抛开脑袋空白
糊里糊涂也不坏

(zz)我不想再忍了,我所知道的奶业内幕.一个曾经在收奶员的岗位上的工作者的表述.

http://cache.tianya.cn/techforum/content/738/1187.shtml
http://cache.tianya.cn/techforum/content/738/1187.shtml

正在研究XMLHTTP如何正确传送大于7F(127)的二进制数据

var sss=(String.fromCharCode(127));
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.Open("POST","x.aspx",false);
xmlhttp.send(sss); 


如果是127的二进制数据接收到的数据没有问题,是7F.

var sss=(String.fromCharCode(128));
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.Open("POST","x.aspx",false);
xmlhttp.send(sss); 


但是如果是128,接收到的字节数目将变成2,"c2和80"
凡是大于128的数据都变成了双字节。

我不明白那个c2是个什么东东。难道是传说中的。。。xxxencode,还是utf?

再或者,莫非这就是传说中的默认application/x-www-form-urlencoded!就是这小样?

所以要正确传送只能做一次BASE64ENCODE。

哎。怎么才能直接传呢?

研究中

.NET 扩展

class Command
{
    public virtual void Execute() { }
}

class InvalidOperationException<T> : InvalidOperationException
    where T : Command
{
    public InvalidOperationException(string message) : base(message) { }
    // some specific information about
    // the command type T that threw this exception
}

static class CommandExtensions
{
    public static void ThrowInvalidOperationException<TCommand>(
        this TCommand command, string message) 
        where TCommand : Command
    {
        throw new InvalidOperationException<TCommand>(message);
    }
}

class CopyCommand : Command
{
    public override void Execute()
    {
        // after something went wrong:
        this.ThrowInvalidOperationException("Something went wrong");
    }
}

class CutCommand : Command
{
    public override void Execute()
    {
        // after something went wrong:
        this.ThrowInvalidOperationException("Something else went wrong");
    }
}

SQLite的效率...嗯....研究中....

数据库中有20万条数据,批量插入500条。
数据结构完全一样,SQLite用7秒,MYSQL用0.5秒。

google了一下SQLite效率问题,居然看到“SQLite 效率太低,批量插入1000条记录,居然耗时 2 分钟!”

仔细往下看,用事务能显著提升性能。
嗯,仔细研究一下SQLite的性能问题好了。

于是我使用了事务,发现插入500条数据仅仅需要0.4秒了。
果然。。。

SQLite 提示database disk image is malformed

SQLite有一个很严重的缺点就是不提供Repair命令。
导致死亡提示database disk image is malformed
有很多种可能,比如,磁盘空间不足,还有就是写入数据过程中突然掉电。

刚才在操作一个26万行的数据表的时候,突然掉电
再次执行SELECT指令就出现了database disk image is malformed
由于不知道错误出在哪个地方,无从修复
运行
PRAGMA integrity_check
发现
*** in database main ***
On tree page 120611 cell 0: 3 of 4 pages missing from overflow list starting at 120617
On tree page 120616 cell 0: 3 of 4 pages missing from overflow list starting at 120621
On tree page 3309 cell 0: 3 of 4 pages missing from over
--------------------------------------------------------------------------------------
google了一下,从N多劳苦大众的经验获知,如果遇到这种情况基本宣告SQLite死亡
居然没办法修复。
可爱的MYSQL 可以用REPAIR TABLE 来修复,可是SQLite就没有REPAIR TABLE
MS SQL SERVER 也有Repair 方法,为什么SQLite就不来一个呢??
恩,有时候趋之若鹜并不一定是好事

FireFox里面textarea自动换行的解决之道

FF下面textarea无法自动换行似乎是一个由来已久的BUG,实际上加上wrap="virtual"也没用!!!
wrap=hard也没用。就是没有解决办法。恩。等ff自己修复好了
«789101112131415161718192021»

Powered By Z-Blog 1.8 Walle Build 100427
Copyright Sipo.