2023年6月21日发(作者:)

SQL语句中的output⽤法 1 private void button2_Click(object sender, RoutedEventArgs e) 2 { 3 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111")) 4 { 5 (); 6

7 using (SqlCommand cmd = Command()) 8 { 9 dText = "insert [DBData].[dbo].[T_Student] (Number,Name,Score) output values('012345','LiLei','89')";10 long id = (long)eScalar(); //ExecuteScalar():执⾏查询,返回结果集中的第⼀⾏的第 ⼀列11 ("操作成功: i=" + ng());12 }13 }14

15 }16

17

18

19 private void button2_Click(object sender, RoutedEventArgs e)20 {21 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111"))22 {23 ();24

25 using (SqlCommand cmd = Command())26 {27 dText = "Select * from [DBData].[dbo].[T_Student] where score<160";28 using (SqlDataReader reader = eReader())29 {30 while (())31 {32 (ing(2)); //获取指定列的字符串的值33 }34 }35 }36 }37

38 }39

40

41 private void button2_Click(object sender, RoutedEventArgs e)42 {43 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111"))44 {45 ();46 using (SqlCommand cmd = Command())47 {48 dText = "select * from [DBData].[dbo].[T_Student] where Score<@Score";49 (new SqlParameter("@Score", 80));50

51 DataSet dataset = new DataSet();52

53 //SqlDataAdapter是⼀个帮我们把SqlCommand查询结果填充到DataSet中的类54 SqlDataAdapter adapter = new SqlDataAdapter(cmd);55 (dataset);56

57 DataTable dt = [0];58 }59 }60

61 ("操作成功");62

63 }

2023年6月21日发(作者:)

SQL语句中的output⽤法 1 private void button2_Click(object sender, RoutedEventArgs e) 2 { 3 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111")) 4 { 5 (); 6

7 using (SqlCommand cmd = Command()) 8 { 9 dText = "insert [DBData].[dbo].[T_Student] (Number,Name,Score) output values('012345','LiLei','89')";10 long id = (long)eScalar(); //ExecuteScalar():执⾏查询,返回结果集中的第⼀⾏的第 ⼀列11 ("操作成功: i=" + ng());12 }13 }14

15 }16

17

18

19 private void button2_Click(object sender, RoutedEventArgs e)20 {21 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111"))22 {23 ();24

25 using (SqlCommand cmd = Command())26 {27 dText = "Select * from [DBData].[dbo].[T_Student] where score<160";28 using (SqlDataReader reader = eReader())29 {30 while (())31 {32 (ing(2)); //获取指定列的字符串的值33 }34 }35 }36 }37

38 }39

40

41 private void button2_Click(object sender, RoutedEventArgs e)42 {43 using (SqlConnection conn = new SqlConnection("Data Source=XX;Initial Catalog=DBData;User ID=sa;Password=111111"))44 {45 ();46 using (SqlCommand cmd = Command())47 {48 dText = "select * from [DBData].[dbo].[T_Student] where Score<@Score";49 (new SqlParameter("@Score", 80));50

51 DataSet dataset = new DataSet();52

53 //SqlDataAdapter是⼀个帮我们把SqlCommand查询结果填充到DataSet中的类54 SqlDataAdapter adapter = new SqlDataAdapter(cmd);55 (dataset);56

57 DataTable dt = [0];58 }59 }60

61 ("操作成功");62

63 }