qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問(wèn) http://qaseven.github.io/

          SQL中存儲(chǔ)過(guò)程的創(chuàng)建和使用

           如何創(chuàng)建存儲(chǔ)過(guò)程
          user testdatabase(數(shù)據(jù)庫(kù)名稱)
          go
          create procedure testname(存儲(chǔ)過(guò)程名稱)
          @test1 int, @test2 nvarchar(50)
          as
          insert into testtable values(@test1,@test2)
          return
          //select * from users where truename like '%[王劉]%' //只能分詞查詢,查詢姓劉和姓王的信息
          2 如何使用
          public string[] TestLogin(string uname, string upwd)
          {
          try
          {
          SqlCommand cmd = new SqlCommand();
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "User_Login";//存儲(chǔ)過(guò)程名
          cmd.Connection = conn;
          cmd.Parameters.Clear();
          cmd.Parameters.Add("@uname", SqlDbType.NVarChar, 100).Value = uname;
          cmd.Parameters.Add("@upwd", SqlDbType.NVarChar, 100).Value = upwd;
          string[] result = new string[3];
          conn.Open();
          SqlDataReader dr = cmd.ExecuteReader();
          if (dr.Read())
          {
          result[0] = dr["qx"].ToString();
          result[1] = dr["tname"].ToString();
          result[2] = dr["unitid"].ToString();
          dr.Close();
          return result;
          }
          else
          {
          return null;
          }
          }
          catch (Exception e)
          {
          throw e;
          }
          finally
          {
          conn.Close();
          }
          }

          posted on 2014-03-18 10:45 順其自然EVO 閱讀(442) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫(kù)

          <2014年3月>
          2324252627281
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 阿勒泰市| 吴川市| 江陵县| 丰都县| 襄樊市| 陵川县| 江都市| 西华县| 长垣县| 河源市| 大关县| 永顺县| 通山县| 湘潭市| 平果县| 临邑县| 沾化县| 新巴尔虎右旗| 巴东县| 铅山县| 花莲市| 和平县| 建平县| 阳西县| 平陆县| 贵溪市| 台中市| 大冶市| 阿拉善盟| 望谟县| 苏尼特左旗| 湘阴县| 平罗县| 巴马| 嘉义县| 湖北省| 南康市| 义乌市| 泰安市| 凤台县| 忻州市|