Skip to content

Instantly share code, notes, and snippets.

@whsheng
whsheng / geo2address
Last active August 29, 2015 14:11
通过google服务将经纬度转换为地址描述
/// <summary>
/// 通过google将经纬度转换为地址描述
/// </summary>
/// <param name="dlon"></param>
/// <param name="dlat"></param>
public static void geo2address(double dlon,double dlat)
{
string sURL = "http://maps.googleapis.com/maps/api/geocode/json?latlng={0},{1}";
string tagURL = string.Empty;
CookieCollection cookies = new CookieCollection();
@whsheng
whsheng / md5hash
Created December 9, 2014 03:33
对字符串进行哈希编码
static string GetMd5Hash(MD5 md5Hash, string input)
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
@whsheng
whsheng / describe
Created December 6, 2014 09:36
在sql server中显示指定数据表的结构
CREATE FUNCTION dbo.describe (@TABLENAME varchar(50))
returns table
as
RETURN
(
SELECT TOP 1000 column_name AS [ColumnName],
IS_NULLABLE AS [IsNullable],
DATA_TYPE + '(' + CASE
WHEN DATA_TYPE = 'varchar' or DATA_TYPE = 'char' THEN
CASE
@whsheng
whsheng / 直接备份_恢复数据表
Created November 12, 2014 08:33
使用直接拷贝的方法备份MySQL数据表的方法。
用直接拷贝的方法备份恢复
根据本章前两节的介绍,由于MySQL的数据库和表是直接通过目录和表文件实现的,因此直接复制文件来备份数据库数据,对MySQL来说特别方便。而且自MySQL 3.23起MyISAM表成为缺省的表的类型,这种表可以为在不同的硬件体系中共享数据提供了保证。
当使用直接拷贝的方法备份时,尤其要注意表没有被使用,你应该首先对表进行读锁定。
在MySQL中备份一个表,需要三个文件:
对于MyISAM表:
@whsheng
whsheng / MySQL中复制表结构
Created November 12, 2014 08:29
MySQL中快速复制表结构
mysql> create table a like users; //复制表结构
mysql> create table b select * from users limit 0; //复制表结构
@whsheng
whsheng / insert_update
Created November 10, 2014 09:22
在MSSQL下,如果某条记录不存在,则插入,否则更新
begin tran
if exists (select * from std_UserObj with (updlock,serializable) where UserID = 1102 and ObjectID = 10078)
begin
update std_UserObj
set RelationShip = '妈妈'
where UserID = 1102 and ObjectID = 10078
end
else
begin
insert std_UserObj (UserID,ObjectID,RelationShip)
@whsheng
whsheng / gist:ddd3cdd41a784b6d2e13
Last active August 29, 2015 14:07
Conversion Between DataTable and List in C#
/* Source:http://www.codeproject.com/Tips/784090/Conversion-Between-DataTable-and-List-in-Csharp */
/*Converts DataTable To List*/
public static List<TSource> ToList<TSource>(this DataTable dataTable) where TSource : new()
{
var dataList = new List<TSource>();
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
var objFieldNames = (from PropertyInfo aProp in typeof(TSource).GetProperties(flags)
select new { Name = aProp.Name,
Type = Nullable.GetUnderlyingType(aProp.PropertyType) ?? aProp.PropertyType }).ToList();
@whsheng
whsheng / UspOutputData.sql
Created October 9, 2014 12:22
将SQL Server中的数据表内容导出成Insert Into语句
CREATE PROCEDURE [dbo].[UspOutputData]
@tablename sysname
AS
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectId int
declare @objectname sysname
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
// 此处代码来源于博客【在.net中读写config文件的各种方法】的示例代码
// http://www.cnblogs.com/fish-li/archive/2011/12/18/2292037.html