From 84bf282bb9c8708c5b91c8580da6ee3fbec7797b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E7=A8=8B=E7=A5=A5?= <842143662@qq.com> Date: Sat, 26 Jun 2021 09:25:00 +0000 Subject: [PATCH] WebForm --- .../SqlHelper.cs" | 85 ++++++++++++ .../WebForm1.aspx" | 68 +++++++++ .../WebForm1.aspx.cs" | 130 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SqlHelper.cs" create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/WebForm1.aspx" create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/WebForm1.aspx.cs" diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SqlHelper.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SqlHelper.cs" new file mode 100644 index 0000000..c10c5e7 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SqlHelper.cs" @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Web; + +namespace WebApplication1 +{ + public class SqlHelper + { + private static string constr = "server=. ; uid=sa ; pwd=123456 ; database=Student_db"; + + private SqlConnection con = null; + + public SqlHelper() + { + con = new SqlConnection(constr); + } + + public DataTable Get(string sql , SqlParameter[] pars) + { + try + { + if (con.State == ConnectionState.Closed) + { + con.Open(); + } + SqlCommand cmd = new SqlCommand(sql, con); + + if (pars != null) + { + cmd.Parameters.AddRange(pars); + } + SqlDataAdapter sda = new SqlDataAdapter(cmd); + DataSet ds = new DataSet(); + sda.Fill(ds); + return ds.Tables[0]; + } + catch (Exception e) + { + + throw new Exception(e.Message.ToString()); + } + finally + { + if (con != null) + { + con.Close(); + } + } + } + + public bool Execute(string sql , SqlParameter[] pars) + { + try + { + if (con.State == ConnectionState.Closed) + { + con.Open(); + } + SqlCommand cmd = new SqlCommand(sql, con); + if ( pars != null) + { + cmd.Parameters.AddRange(pars); + } + + int result = cmd.ExecuteNonQuery(); + return result > 0 ? true : false; + } + catch (Exception e) + { + + throw new Exception (e.Message.ToString()); + } + finally + { + if (con != null) + { + con.Close(); + } + } + } + } +} \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/WebForm1.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/WebForm1.aspx" new file mode 100644 index 0000000..295fc20 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/WebForm1.aspx" @@ -0,0 +1,68 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> + + + + +
+ +