C# 编写SQL SERVER 2005 的存储过程
以下是一个查询IP地址归属地的CLR存储过程,三步:
1、用C#来做DLL,代码如下:
//====================================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
public class AddrInfo
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void getAddrInfo(SqlString ip, out SqlString info)
{
using (SqlConnection connection = new SqlConnection("context connection=true"))
{
//IP地址转为数字
string[] tmp = ip.Value.Split(new string[]{"."},StringSplitOptions.None);
Int64 ipn = ToInt(ToBinary(tmp[0]) + ToBinary(tmp[1]) + ToBinary(tmp[2]) + ToBinary(tmp[3]));
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "select addr_info from CZIP where ipn1<="
+ ipn.ToString() + " and ipn2>="
相关文档:
软件 : Sql Server 2005
这里并不是SQL语法大全,以下是常用的语句,对(数据库、表、字段、数据)的增删改查,如果需要详细全面的Transact-SQL语句,可以查Sql Server联机丛书,那里是最全的资料,一般安装Sql Server都会默认安装。
打开Sql Server联机丛书
开始 à 程序 à&n ......
根据宽度来决定显示的字符串长度 (C#,VS2005)
如果 lable长度固定但字符串长度可变,如果超过了lable显示的长度时,希望用 ...代替剩下的字符,这时需要一个函数
Graphics.MeasureString
具体代码如下
public string Abbreviation(string str)
{
&nbs ......
通过一个实际的例子来介绍。其中重载==,!=,Equal,GetHashCode函数。
public class Record
{
public string[] arr = null;
public bool hasEqual = false;
//重载一个下标运算符号
public string this[int index]
{
get
{
return arr[index];
}
set
{
arr[index] = value;
}
}
public override int GetHas ......
由于项目需要,要使用c#描画高频实时曲线.
但是在C#下由于描画图像使用的是GDI+,描画效率很有问题.一旦曲线太多,就会造成CPU使用率直线上升,马上飙升到100%.
在GDI+下使用双缓冲也无济于事,双缓冲本身只会解决曲线多的时候全屏闪烁问题,但描画效率还是严重低下.
其间用过多种解决方案:DRECT3D,DRIRECT2D,GDI,,,,,等等等等 ......
在使用CLR存储过程中遇到的一些问题,在这里进行记录:
打开CLR的支持
--在Sql Server中执行这段代码可以开启CLR
exec sp_configure 'show advanced options', '1';
go
reconfigure;
go
exec sp_configure 'clr enabled', '1'
go
reconfigure;
exec sp_c ......