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 0000000000000000000000000000000000000000..c10c5e78d115f1912d878fcf65b16b3ff08fca72 --- /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 0000000000000000000000000000000000000000..295fc20370c7356a75b1645e91fcc0497cd13885 --- /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" %> + + + + +
+ +