????????洢????????????????
????1.?????????洢????????????????????????????????????????????
????2.????洢??????????????????(output)???????????????????????
????3.?洢????????????????????????????У???????????????????????????????????????????????????????????????????????????λ??FROM????????檔
?????????洢????????
????1.????????? – ????????б????洢???????????????
????2.??????黯??????? – ????????????
????3.?????????? – ???SQL???
????4.????????????? – ??????洢?????????
???????洢?????????sp??????????????洢?????????usp???
????????????洢????????"["   ????????????????
????create proc ?洢??????
????@????1        ???????? [=????] [output]??
????@????2        ???????? [=????] [output]??
????...
????as
????SQL???
??????????????????
????????洢?????
????create proc usp_StudentByGenderAge
????@gender nvarchar(10) [='??']??
????@age int [=30]
????as
????select * from MyStudent where FGender=@gender and FAge=@age
??????д洢?????
????Situation One(???????????):
????exec usp_StudentByGenderAge
????Situation Two(???????????????):
????exec usp_StudentByGenderAge '?'??50
?????????????????        exec usp_StudentByGenderAge @age=50??@gender='?'
??????洢??????????
????alter proc usp_StudentByGenderAge
????@gender nvarchar(10) [='??']??
????@age int [=30]??
????--??output????ò??????????洢?????и?????????
????@recorderCount int output
????as
????select * from MyStudent where FGender=@gender and FAge=@age
????set @recorderCount=(select count(*) from MyStudent where FGender=@gender and FAge=@age)
????--output??????????????????????????????????????????洢????????????????????????洢?????????????????е?????????????????????????(??C#?е?out????????)
????????(????????????)?????洢??????滹??????????????????? @recorderCountд?????洢??????к?????????????????????????????????????????????????@count??????(@count?????????????usp_StudentByGenderAge?????洢?????????????????????????????@count)
????declare @count int
????exec usp_StudentByGenderAge @recorderCount=@count output
????print @count
?????塢???洢?????????
????1???洢???????
create proc usp_page
@page int??          ---??????????????
@number int??   ---???????????????
as
begin
select * from
--С??????????????????????к?????
(
select  ROW_NUMBER() over(order by(Fid))  as number
from MyStudent
) as t
where t.number>= (@number-1)*@page+1 and t.number<=@number*@page
end
????2???????Ч???????ADO.NET????
1 private void button1_Click(object sender?? EventArgs e)
{
2 ????string connStr = @"server=.sqlexpress;database=MyDB;integrated security=true";
3 ????using (SqlConnection conn = new SqlConnection(connStr))
4 ????{
5 ????????//???????????
6???????? conn.Open();
7 ????????//??洢?????????Command????????
8 ????????string usp = "usp_page";
9 ????????using (SqlCommand cmd = new SqlCommand(usp?? conn))
10 ????????{
11 ????????????//??е???洢???????
12 ????????????cmd.CommandType = CommandType.StoredProcedure;
//textBox1.Text???????????????
13 ????????????cmd.Parameters.AddWithValue("@page"?? textBox1.Text.Trim());
14 ????????????//textBox.Text??????????????
15 ????????????cmd.Parameters.AddWithValue("@number"?? textBox2.Text.Trim());
16 ????????????//??list?????????????
17 ????????????List<Person> p = new List<Person>();
18 ????????????using (SqlDataReader reader = cmd.ExecuteReader())
19 ????????????{
20 ????????????????if (reader.HasRows)
21 ????????????????{
22 ????????????????????while (reader.Read())
24 ????????????????????{
25 ????????????????????????Person p1 = new Person();
26 ????????????????????????p1.FName = reader.GetString(1);
27 ????????????????????????p1.FAge = reader.GetInt32(2);
28 ????????????????????????p1.FGender = reader.GetString(3);
29???????????????????????? p1.FMath = reader.GetInt32(4);
30 ????????????????????????p1.FEnglish = reader.GetInt32(5);
31 ????????????????????????p.Add(p1);
32 ????????????????????}
33 ????????????????}
34 ????????????}
35 ????????????dataGridView1.DataSource = p;
36 ????????}
37 ????}
38 }