c#에서 스토리지 프로세스 수행 방법

30132 단어 저장 프로세스
  1 using System;

  2 using System.Collections.Generic;

  3 using System.ComponentModel;

  4 using System.Data;

  5 using System.Drawing;

  6 using System.Linq;

  7 using System.Text;

  8 using System.Threading.Tasks;

  9 using System.Windows.Forms;

 10 

 11 namespace       

 12 {

 13     using System.Data.SqlClient;

 14     public partial class Form1 : Form

 15     {

 16         public Form1()

 17         {

 18             InitializeComponent();

 19         }

 20         string connStr = "Data Source=.;Initial Catalog=MySchoolMoreData;Integrated Security=True";

 21 

 22         #region             +void btnNoPARAMAS_Click(object sender, EventArgs e)

 23         /// <summary>

 24         ///            

 25         /// </summary>

 26         /// <param name="sender"></param>

 27         /// <param name="e"></param>

 28         private void btnNoPARAMAS_Click(object sender, EventArgs e)

 29         {

 30             //SqlDataAdapter da = new SqlDataAdapter("select * from Student", connStr);

 31             SqlDataAdapter da = new SqlDataAdapter("usp_getAllStuInfo", connStr);

 32             DataTable dt = new DataTable();

 33             da.Fill(dt);

 34             this.dgvList.DataSource = dt;

 35         } 

 36         #endregion

 37 

 38         #region              +void btnHasParamas_Click(object sender, EventArgs e)

 39         /// <summary>

 40         ///             

 41         /// </summary>

 42         /// <param name="sender"></param>

 43         /// <param name="e"></param>

 44         private void btnHasParamas_Click(object sender, EventArgs e)

 45         {

 46             SqlDataAdapter da = new SqlDataAdapter("usp_getStuInfoBySexAndCname", connStr);

 47             //1.         ,                ,     sql      

 48             da.SelectCommand.CommandType = CommandType.StoredProcedure;

 49             //2.             ,  :                

 50             SqlParameter[] ps = { 

 51                                 new SqlParameter("@cname",this.cboClass.Text),//Text                

 52                                 new SqlParameter("@Sex",rdoMale.Checked?" ":" ")

 53                                 };

 54             //3.           

 55             da.SelectCommand.Parameters.AddRange(ps);

 56             DataTable dt = new DataTable();

 57             da.Fill(dt);

 58             this.dgvList.DataSource = dt;

 59         } 

 60         #endregion

 61 

 62         #region            Dgv        +void Form1_Load(object sender, EventArgs e)

 63         /// <summary>

 64         ///            Dgv       

 65         /// </summary>

 66         /// <param name="sender"></param>

 67         /// <param name="e"></param>

 68         private void Form1_Load(object sender, EventArgs e)

 69         {

 70             #region         

 71             SqlDataAdapter da = new SqlDataAdapter("select classid ,classname from classes where classid<@num", connStr);

 72             SqlParameter p = new SqlParameter("@num", 15);

 73             SqlParameter p2 = new SqlParameter("@num2", 150);

 74             da.SelectCommand.Parameters.Add(p2);

 75             da.SelectCommand.Parameters.Add(p);

 76             DataTable dt = new DataTable();

 77             da.Fill(dt);

 78             this.cboClass.DisplayMember = "classname";

 79             this.cboClass.ValueMember = "classid";

 80             this.cboClass.DataSource = dt;

 81             #endregion

 82 

 83             LoadDgvData();

 84         } 

 85         #endregion

 86 

 87         int pageIndex = 1; //     

 88         //int pageCount = 5;

 89 

 90         #region                  +void btnOutput_Click(object sender, EventArgs e)

 91         /// <summary>

 92         ///                 

 93         /// </summary>

 94         /// <param name="sender"></param>

 95         /// <param name="e"></param>

 96         private void btnOutput_Click(object sender, EventArgs e)

 97         {

 98             SqlDataAdapter da = new SqlDataAdapter("usp_GetCountByCnameAndSex", connStr);

 99             //1.         ,                ,     sql      

100             da.SelectCommand.CommandType = CommandType.StoredProcedure;

101             //2.             ,  :                

102             SqlParameter[] ps = { 

103                                 new SqlParameter("@cname",this.cboClass.Text),//Text                

104                                 new SqlParameter("@Sex",rdoMale.Checked?" ":" "),

105                                 //106                                 //        ,                      Value   

107                                 new SqlParameter("@totalCount",100),

108                                 new SqlParameter("@cnt",SqlDbType.Int),

109                                 new SqlParameter("@result",SqlDbType.Int)

110                                 };

111             //3.            ,                     ,        ,       

112             ps[0].Direction = ParameterDirection.Input;//    input,        

113             //ps[2].Direction = ParameterDirection.Output;//            

114             //

115             ps[3].Direction = ParameterDirection.Output;

116             ps[4].Direction = ParameterDirection.ReturnValue;

117             //3.           

118             da.SelectCommand.Parameters.AddRange(ps);

119             DataTable dt = new DataTable();

120             da.Fill(dt);

121             this.dgvList.DataSource = dt;

122             this.lblMsg.Text = "" + ps[2].Value + ",        :" + ps[3].Value + ",    :" + ps[4].Value;

123         } 

124         #endregion

125 

126         #region     + void btnNext_Click(object sender, EventArgs e)

127         /// <summary>

128         ///    

129         /// </summary>

130         /// <param name="sender"></param>

131         /// <param name="e"></param>

132         private void btnNext_Click(object sender, EventArgs e)

133         {

134             if (pageIndex.ToString() == System.Configuration.ConfigurationManager.AppSettings["totalPageCount"])

135             {

136                 MessageBox.Show("      ");

137                 return;

138             }

139             pageIndex++;

140             LoadDgvData();

141         } 

142         #endregion

143 

144         #region        +void LoadDgvData()

145         /// <summary>

146         ///       

147         /// </summary>

148         private void LoadDgvData()

149         {

150             string count = System.Configuration.ConfigurationManager.AppSettings["pageCount"];

151             SqlParameter[] ps ={

152                                 new SqlParameter("@pageIndex",pageIndex),

153                                 new SqlParameter("@pageCount",count),

154                                 new SqlParameter("@totalPageCount",SqlDbType.Int)

155                                };

156             ps[2].Direction = ParameterDirection.Output;//            --    

157             this.dgvList.DataSource = SqlHelper.ExecuteTable("usp_getPageData", CommandType.StoredProcedure, ps);

158             System.Configuration.ConfigurationManager.AppSettings["totalPageCount"] = ps[2].Value.ToString();

159         } 

160         #endregion

161 

162         #region     +void btnPre_Click(object sender, EventArgs e)

163         /// <summary>

164         ///    

165         /// </summary>

166         /// <param name="sender"></param>

167         /// <param name="e"></param>

168         private void btnPre_Click(object sender, EventArgs e)

169         {

170             if (pageIndex == 1)

171             {

172                 MessageBox.Show("      ");

173                 return;

174             }

175             pageIndex--;

176             LoadDgvData();

177         } 

178         #endregion

179     }

180 }

좋은 웹페이지 즐겨찾기