正确使用DataSet和DataReader(转载)

July 26, 2006
正确使用DataSet和DataReader
Filed under: SQL&DB AccessingBy Riven Huang 2006.07.26
参照
Why I Don't Use DataSets in My ASP.NET Applications(by Scott Michell)
http://aspnet.4guysfromrolla.com/articles/050405-1.aspxPerformance Comparison: Data Access Techniques
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetarch031.asp首先需要理解DataSet 和 DataReader的设计目标:
DataSet可以理解成一个小型的,存在于内存中的数据库,包含多个data table,table之间
可存在约束关系.
DataSet和数据库无关,由DataAdapter来负责对数据库的处理,一旦数据填充结束,就和数据库
断开连接.
DataSet对XML的支持比较好.DataReader可以理解成程序和数据库之间的桥梁.只能顺序的,从数据库中读取记录.
DataReader是和数据库相关的,所以存在sql, ole等多个版本的DataReader.从使用上来看,使用DataReader需要以下步骤:
// 1. 建立连接
SqlConnection myConnection = new SqlConnection(conn);// 2. 执行查询
SqlCommand myCommand = new SqlCommand(myConnection, sqlText);SqlReader myReader = myCommand.ExecuteReader();// 3. Read
while(myReader.Read())
{}// 4. Close connection
myConnection.Close();使用DataSet需要以下步骤:
// 1. 建立连接
SqlConnection myConnection = new SqlConnection(conn);// 2. 生成command 和 adapter
SqlCommand myCommand = new SqlCommand(myConnection, sqlText);
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);// 3. 生成dataset并填充
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);// 4. Close connection
myConnection.Close();如果使用UIControlo显示数据,对于dataset和datareader的操作是相同的:
把dataset或datareader赋给control的DataSource属性,
再调用control的DataBind()方法.比较:
DataSet的性能比DataReader差很对,同时占用大量的内存.何时使用DataSet:
1.数据传输.
2.桌面应用.

Supreme Commander的配置

Minimum Requirements
CPU: Athlon 64 3000+/Intel 2.8ghz
Graphics: Nvidia 6600/X800GTO (SM 2.0)
RAM: 768Mb/1Gb on Windows Vista
HDD: 6GB
Internet: 256k+
Optical Drive: DVD
Software: DX9.0c with Windows XPRecommended Requirements
CPU: Dual-core CPU (Athlon X2/Pentium D)
Graphics: Nvidia 7800GTX/ATI X1800XT (SM 3.0) or DX10 equivalent
RAM: 1.5Gb
HDD: 6GB
Internet: 512k+ (128k+ upstream)
Optical Drive: DVD
Software: DX10 with Windows Vista
如果我的机器能够长大...它现在一定已经老得快不能自主呼吸了。

试了几个FireFox扩展

1.Better Gmail 0.6.1
  改皮肤的功能不错,鼠标到哪里,哪封信就加亮。
  label color
  macro
2.Clipmarks 2.0.4
  作用是方便选中网页中的某一处,然后复制。
  似乎让机器变慢了,且需要登录。禁用。
3.Download Statusbar 0.9.4.6
  在状态栏显示当前下载状态,可以停止/继续。
4.United States English Dictionary 2.0.0.6
 原以为是词霸类的软件。用于拼写检查。 禁用。
" This extension packages a subset of the original English wordlist created by Kevin Atkinson for Pspell and Aspell and thus is covered by his original LGPL license. The affix file is a heavily modified version of the original english.aff file which was released as part of Geoff Kuenning's Ispell and as such is covered by his BSD license."[ http://www.blogzilla.info/spellchecker/

Wordlist Creator(转载)

Wordlist Creator

via Freeware Home -- new additions on May 14, 2007

Wordlist Creator creates an alphabetical list of the words contained in a text file. Useful if you need to make a dictionary or otherwise provide a list of keywords as a database for example for use with Autocompletion software. (in Business and Productivity)

 
 

Things you can do from here:

 
 



--
重剑无锋,大巧不工。

Byte array <=> String in C# .Net

Byte myBytes1[]   =   myMemoryStream.ToArray();
String str   =   System.Text.Encoding.Default.GetString( myBytes1  );
Byte myBytes2[]=System.Text.Encoding.Default.GetBytes( str )   ;

Byte   myBytes1[]   =   myMemoryStream.ToArray   ();
String   str   =   (new   UnicodeEncoding()).GetString( myBytes1 );
Byte   myBytes2[]   =   (new   UnicodeEncoding()).GetBytes( str )   ;

Windows中的计时器(SetTimer和CreateWaitableTimer)

Windows中的计时器(SetTimer和CreateWaitableTimer)   
Timers (SetTimer and CreateWaitableTimer) in Windows
       
1.SetTimer
下面的例子创建了一个计时器(不与窗口相关联),该计时器过程函数建了20个消息框。
The following example creates a timer (that is not attached to a window) whose Timer Procedure creates 20 Message Boxes

#include <windows.h>

class foo_class {
  static int counter;
public:
  //static函数,相当于全局
  static void  __stdcall timer_proc(HWND,unsigned int, unsigned int, unsigned long) {
    if (counter++ < 20)
      MessageBox(0,"Hello","MessageBox",0);
    else
      PostQuitMessage(0);
  }
};

int foo_class::counter=0;

WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) {

//第1个参数,MSDN中指出如果置为NULL,即0,不与窗口相关联。
//If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
//第2个参数会被忽略
//第3个参数,300毫秒触发一次
//第4个参数,触发时由函数foo_class::timer_proc响应
int iTimerID = SetTimer(0, 0, 300, foo_class::timer_proc);
  MSG m;
//这是消息循环
  while (GetMessage(&m,0,0,0)) {
    TranslateMessage(&m);
    DispatchMessage(&m);

   }
  return 1;
}

2.CreateWaitableTimer
这个例子演示如何在windows中使用计时器。
计时器被设计为(1)在第1次调用CreateWaitableTimer后2秒触发,(2)此后每3/4秒触发一次。
#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <process.h>
#include <stdio.h>

unsigned __stdcall TF(void* arg) {
  HANDLE timer=(HANDLE) arg;

  while (1) {
    //此处,进程间通信的接收方
    //timer是命名的,因此进程间或线程间没有区别
    WaitForSingleObject(timer,INFINITE);
    printf(".");
  }

}

int main(int argc, char* argv[]) {
  //创建,命名为0,也可以是LPCTSTR,字符串
  //其他进程可以通过OpenWaitableTimer获得此timer的句柄,并对之进行SetWaitableTimer
  HANDLE timer = CreateWaitableTimer(
    0,
    false, // false=>will be automatically reset
    0);    // name

  LARGE_INTEGER li;

  const int unitsPerSecond=10*1000*1000; // 100 nano seconds

  // Set the event the first time 2 seconds
  // after calling SetWaitableTimer
  //2秒
  li.QuadPart=-(2*unitsPerSecond);
  //通过句柄设置timer
  SetWaitableTimer(
    timer,
    &li,
    750,   // Set the event every 750 milli Seconds
    0,
    0,
    false);
  //用TF函数启动worker线程
  _beginthreadex(0,0,TF,(void*) timer,0,0);

  // Wait forever,
  while (1) ;

  return 0;
}

参考:
1.[http://www.adp-gmbh.ch/win/misc/timer.html ]
2.[http://support.microsoft.com/kb/184796],中文的

能用google cache的firefox extention

  安装了CustomizeGoogle is a Firefox extension that enhances Google search results by adding extra information (like links to Yahoo, Ask.com, MSN etc) and removing unwanted information (like ads and spam).在[ http://www.customizegoogle.com/]。因为看到小众软件上提到这个extention。
  不错,真的能看cache了。

  测试另一个extention,名为torbutton,作为代理。用了之后超时,可能无法访问内置的代理。unistall,继续用SwitchProxy Tool。

UFC笔记

UFC录像两段
作为外行看到的技术
 肘击
 用肘夹住对方的头,膝盖顶头
 击打对方关或颈部,目的似乎是使颈部受力,而失去平衡
 用腿夹住对方的腰,使自己在地面时保持住,或使自己控制地面的对方
力量很重要,速度和耐力也很重要。

MIT开放课程 Structure and Interpretation of Computer Programs video下载

MIT开放课程 Structure and Interpretation of Computer Programs video下载:

  教材Structure And Interpretation Of Computer Programs - Mit Press,
  使用Scheme语言
  有免费工具MIT Scheme,
  在[ http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/Tools/detail/Guide-to-MIT-Scheme.htm]
  支持Windows和Linux。

视频下载:
1.flash或mp4
MIT OCW - 6.001 Structure and Interpretation of Computer Programs (1986)
[http://www.archive.org/details/MIT_Structure_of_Computer_Programs_1986]

[ http://ia350602.us.archive.org/3/items/MIT_Structure_of_Computer_Programs_1986/]

2.avi(Divx)或mpg, bit torrent supported
[http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ ]

  感谢刘典先生推荐[Structure And Interpretation Of Computer Programs - Mit Press],
他告诉我这本书能帮助确定"机制与策略"的分离。
  感谢李粲先生同意刘典先生推荐这本书,李粲先生与刘典先生一同指出《Unix程序设计艺术》中的"机制与策略"正符合我所说的原则。
  感谢不记得什么时间谁请的烤牛肉,它让我们的交流很畅快。