using System.Security.Cryptography;
using System.IO;
using System.text;
/// <summary>
/// 加密
/// </summary>
/// <param name="str"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Encode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
prov ......
using System.Security.Cryptography;
using System.IO;
using System.text;
/// <summary>
/// 加密
/// </summary>
/// <param name="str"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Encode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
prov ......
C#使用System.Data.OracleClient连接Oracle数据库。之前在WinXP上正常运行的程序移植到 Windows 2008 x64上之后就连不上数据库了,错误信息如下:
尝试加载 Oracle客户端库时引发BadImageFomatException。如果在安装32位Oracle客户端组件的情况下以64位模式运行,将出现此问题。
错误原因是原来WinXP机子上所安装的OracleInstantClient是32位,所以编译的程序所用的 OracleClient也是32位的,从而导致兼容问题。当然,如果在64位操作系统上重新安装64位的Oracle客户端再重新编译程序也是能解决问题的。这里我们介绍一种简单的方法来移植程序。
实际上,System.Data.OracleClient所指向的是PATH环境变量下的oci.dll。因此,我们只要让程序能够找到64位的oci.dll就可以了。方法如下:
1. 下载instantclient-basic-win-x86-64-11.1.0.7.0.zip,并解压,如 C:\instantclient-basic-win-x86-64-11.1。
2. 在系统的环境变量PATH中加入以上路径。
之后再运行程序,程序会依照PATH路径寻找oci.dll,如果遇到32位的oci.dll会自动略过,找到64位的oci.dll就能连接上数据库了。
解决过程中参考了Jeffrey的博文,http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/10/ ......
C#使用System.Data.OracleClient连接Oracle数据库。之前在WinXP上正常运行的程序移植到 Windows 2008 x64上之后就连不上数据库了,错误信息如下:
尝试加载 Oracle客户端库时引发BadImageFomatException。如果在安装32位Oracle客户端组件的情况下以64位模式运行,将出现此问题。
错误原因是原来WinXP机子上所安装的OracleInstantClient是32位,所以编译的程序所用的 OracleClient也是32位的,从而导致兼容问题。当然,如果在64位操作系统上重新安装64位的Oracle客户端再重新编译程序也是能解决问题的。这里我们介绍一种简单的方法来移植程序。
实际上,System.Data.OracleClient所指向的是PATH环境变量下的oci.dll。因此,我们只要让程序能够找到64位的oci.dll就可以了。方法如下:
1. 下载instantclient-basic-win-x86-64-11.1.0.7.0.zip,并解压,如 C:\instantclient-basic-win-x86-64-11.1。
2. 在系统的环境变量PATH中加入以上路径。
之后再运行程序,程序会依照PATH路径寻找oci.dll,如果遇到32位的oci.dll会自动略过,找到64位的oci.dll就能连接上数据库了。
解决过程中参考了Jeffrey的博文,http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/10/ ......
用的是一种很笨的方法,但可以帮助初学者了解访问XML节点的过程。
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1、往<bookstore>节点中插入一个<book>节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个<book>节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.Inne ......
C# ASP.NET里@的妙用
ASP.NET C# string 字符串的前面可以加 @ 可以将转义字符(\)当作普通字符对待。
比如:string str = @"C:\Windows";
如果我们不用 @ 的话,应该是:string str = "C:\\Windows";
@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3。
string str = @"=""=";
@ 字符串中可以任意换行,换行符及缩进空格都计算在字符串长度之内。
string str = @"<script type=""text/javascript"">
<!--
-->
</script>";
由于 @ 的这种特性,我们常将其应用到 SQL 字符串中。
string sql = @"select * from tbl";
@ 只在连续一段字符串中有效,@"abc" + "\\",用 + 将两个字符串连接起来,第二个字符串中没有用 @ 标识,其中的 \ 就成为转义字符。
......
C# ASP.NET里@的妙用
ASP.NET C# string 字符串的前面可以加 @ 可以将转义字符(\)当作普通字符对待。
比如:string str = @"C:\Windows";
如果我们不用 @ 的话,应该是:string str = "C:\\Windows";
@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3。
string str = @"=""=";
@ 字符串中可以任意换行,换行符及缩进空格都计算在字符串长度之内。
string str = @"<script type=""text/javascript"">
<!--
-->
</script>";
由于 @ 的这种特性,我们常将其应用到 SQL 字符串中。
string sql = @"select * from tbl";
@ 只在连续一段字符串中有效,@"abc" + "\\",用 + 将两个字符串连接起来,第二个字符串中没有用 @ 标识,其中的 \ 就成为转义字符。
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Str
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
/*
* connect to Sql Server
*/
string strConnection = "Data Source=ZRQ-PC;";
strConnection+="Initial Catalog=master;Integrated Security=True";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
objConnection.Close();
/**************************************************************/
/*
* connect to access table
*/
//string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
//strConnection += @"D ......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Str
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
/*
* connect to Sql Server
*/
string strConnection = "Data Source=ZRQ-PC;";
strConnection+="Initial Catalog=master;Integrated Security=True";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
objConnection.Close();
/**************************************************************/
/*
* connect to access table
*/
//string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
//strConnection += @"D ......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Str
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
/*
* connect to Sql Server
*/
string strConnection = "Data Source=ZRQ-PC;";
strConnection+="Initial Catalog=master;Integrated Security=True";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
objConnection.Close();
/**************************************************************/
/*
* connect to access table
*/
//string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
//strConnection += @"D ......
SQLServer CodeSmith C#
bigint Int64 Int64
binary Binary System.Byte[]
bit Boolean &n ......
SQLServer CodeSmith C#
bigint Int64 Int64
binary Binary System.Byte[]
bit Boolean &n ......