2014年6月24日 星期二

C# 剖析 地址 regex

string zipCode = "", city = "", district = "", town = "", lin = "", road = "", sec = "", len = "", non = "", no = "", floor = "", at = "";

            var pattern = @"(?<zipcode>(^\d{5}|^\d{3})?)(?<city>\D{2}[縣市])?(?<district>\D+[鄉鎮市區])?(?<town>\D+[村里])?(?<lin>.+[鄰])?(?<road>\D+[路街大道])?(?<sec>.+[段])?(?<len>.+[巷])?(?<non>.+[弄])?(?<no>.+[號])?(?<floor>.+[樓Ff])?(?<at>[之-].+)?";

            Match match = Regex.Match(addr, pattern);

            zipCode = match.Groups["zipcode"].ToString();
            city = match.Groups["city"].ToString();
            district = match.Groups["district"].ToString();
            town = match.Groups["town"].ToString();
            lin = match.Groups["lin"].ToString();
            road = match.Groups["road"].ToString();
            sec = match.Groups["sec"].ToString();
            len = match.Groups["len"].ToString();
            non = match.Groups["non"].ToString();
            no = match.Groups["no"].ToString();
            floor = match.Groups["floor"].ToString();
            at = match.Groups["at"].ToString();

標籤: ,

2014年6月23日 星期一

C# call SQL stored procedure

using System.Data.SqlClient;
using System.Data;

string connStr = "Data Source=(local);Initial Catalog=SinoPacDocDB;Persist Security Info=True;User ID=sa;Password=sa";
        SqlConnection conn = new SqlConnection(connStr);


        SqlCommand cmd = new SqlCommand("Sp_Doc_MyDoc", conn);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Sel_PageSize", 10);
        cmd.Parameters.AddWithValue("@Sel_PageIndex", 0);
        cmd.Parameters.AddWithValue("@UserCode", "103190");

        conn.Open();

        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);
       

        conn.Close();

標籤: