当前位置:编程学习 > C#/ASP.NET >>

各位大哥大姐帮帮忙啊!谢谢

能帮我简单的解释下这些代码吗?急用啊!小弟谢谢了!

1)public static int ExecuteSQLCmd(string strSQL)

       {

           SqlConnection currentConn = new SqlConnection(strConn);

           SqlCommand currentCmd = new SqlCommand(strSQL, currentConn);

           try

           {

              currentConn.Open();

              currentCmd.ExecuteNonQuery();

              currentCmd.Dispose();

              currentConn.Close();

              return 0;

           }

           catch(System.Data.SqlClient.SqlException e)

           {

              throw new Exception(e.Message);

           }

           finally

           {

              currentCmd.Dispose();

              currentConn.Close();

           }

       }

2). public static DataSet ExecuteSQLForDS(string strSQL)

       {

           SqlConnection currentConn = new SqlConnection(strConn);

           try

           {

              currentConn.Open();

              SqlDataAdapter currentDA = new SqlDataAdapter(strSQL, currentConn);

              DataSet ds = new DataSet("ds");

              currentDA.Fill(ds);

              currentDA.Dispose();

              currentConn.Close();

              return ds;

           }

           catch(System.Data.SqlClient.SqlException e)

           {

              throw new Exception(e.Message);

           }

           finally

           {

              currentConn.Close();

           }

       }


3).public bool IsExist(string name)

       {

           SqlConnection con = new SqlConnection(strConn);

           con.Open();

           string strSql;

           strSql = "select ID from [User] where UserName = '" name "'";

           SqlCommand cmd1=new SqlCommand(strSql,con);

           SqlDataReader sdr=cmd1.ExecuteReader();

           if(sdr.HasRows==true)

           {

              sdr.Close();

              con.Close();

              return true;

           }

           else

           {

              sdr.Close();

              con.Close();

              return false;

           }

       }

4).public void AddUser()

       {

           string strSql = "INSERT INTO [User] (UserName, PasswordStr, RealName, Sex, IDName, IDNumber, Education, Province, Address, PostCode, PhoneNumber, MobilePhone, EMail, UserLevel, TotalConsumption)VALUES("

                     "'" this.strUserName "',"

                     "'" Functions.Encrypt(this.Password,1) "',"                     "'" this.RealName "',"

                     "" this.nSex ","

                     "'" this.IDName "',"

                     "'" this.IDNumber "',"

                     "'" this.Education "',"

                     "'" this.Province "',"

                     "'" this.Address "',"

                     "'" this.PostCode "',"

                     "'" this.CallNumber "',"

                     "'" this.Mobile "',"

                     "'" this.Mail "',"

                     "1,'0')";

           try

           {

    RobertSoft.PetStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);

           }

           catch

           {

              throw new Exception("注册失败!请重试!");

           }         

       }

5).public static bool IsSupervisor(string name)

       {

           string strManager = ConfigurationSettings.AppSettings["Manager"];

           string [] names = strManager.Split(',');

           int i;

           for(i=0;i<names.Length;i )

           {

              if(name == names)

              {

                  return true;

              }

           }

           return false;

       }

6).public int ID()

       {

           SqlConnection con = new SqlConnection(strConn);

           con.Open();

           string strSql;

           strSql = "select ID from [User] where UserName = '" strUserName "'";

           SqlCommand cmd1=new SqlCommand(strSql,con);

           int userID=Convert.ToInt32(cmd1.ExecuteScalar());

           con.Close();

           return userID;

       }

--------------------编程问答-------------------- 还真多


 

这些是操作数据库的代码

第1个 执行 增加 删除 修改操作的 (返回INT  等于0  操作失败 大于0操作成功)参数SQL语句

第2个 执行 查询的  (反回 DataSet 数据集  ds.tables[0].rows.count==0 数据为空  !=0 有数据)参数SQL语句

第3个 执行 根据用户名查询用户 资料 参数用户名

第4个添加 用户
--------------------编程问答-------------------- 这些是操作数据库的代码

第1个 执行 增加 删除 修改操作的 (返回INT  等于0  操作失败 大于0操作成功)参数SQL语句

第2个 执行 查询的  (反回 DataSet 数据集  ds.tables[0].rows.count==0 数据为空  !=0 有数据)参数SQL语句

第3个 执行 根据用户名查询用户 资料 参数用户名

第4个添加 用户
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,