当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommand.Dispose方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommand.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.Dispose方法的具体用法?C# SqlCommand.Dispose怎么用?C# SqlCommand.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommand的用法示例。


在下文中一共展示了SqlCommand.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsUpdDel

    public static string InsUpdDel(string query)
    {
        SqlConnection sqlcon = new SqlConnection(connstring);

        SqlCommand sqlcom = new SqlCommand(query, sqlcon);
        //sqlcom.CommandType = CommandType.Text;
        sqlcon.Open();
        try
        {
            // string connstring = ConfigurationManager.ConnectionStrings["connid"].ToString(); //ConfigurationManager.AppSettings["connid"];
            

            sqlcom.ExecuteNonQuery();

            query = "";
            sqlcom.Dispose();
            sqlcon.Close();
            return "true";
        }
        catch(Exception prajwol)
        {
            query = "";
            sqlcom.Dispose();
            sqlcon.Close();
            return prajwol.Message.ToString();
        }
    }
开发者ID:pshreez,项目名称:ASP.NET,代码行数:27,代码来源:Class1.cs

示例2: FilterData

        public DataSet FilterData(ArsonFilterModel filterData)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["UCR_DataEntities"];
            DataSet dsResult = new DataSet();
            using (SqlConnection conn = new SqlConnection(connectionString.ConnectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand();
                    command.Connection = conn;
                    command.CommandText = GenerateArsonORQuery(filterData);
                    command.CommandType = System.Data.CommandType.Text;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = command;

                    conn.Open();
                    adapter.Fill(dsResult);
                    conn.Close();
                    adapter.Dispose();
                    command.Dispose();
                }
                catch (Exception ex)
                {
                    StorageClient.LogError(ex);
                }
            }
            return dsResult;
        }
开发者ID:yogsgit,项目名称:FBIUCRDashboard,代码行数:28,代码来源:DataAccess.cs

示例3: InsertKhachHang

        public string InsertKhachHang(string TenKH, string Gioitinh, string Diachi, string SDT, string LoaiKH, string Ghichu)
        {
            string str = "";
            string sql = "InsertKH";
            //   string sql = "insert NhomSP values (@Manhom, @Tennhom, @NgayCN)";
            SqlConnection con = new SqlConnection(KetNoiDB.getconnect());
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@TenKH", TenKH);
            cmd.Parameters.AddWithValue("@gt", Gioitinh);
            cmd.Parameters.AddWithValue("@DC", Diachi);
            cmd.Parameters.AddWithValue("@SDT", SDT);
            cmd.Parameters.AddWithValue("@LoaiKH", LoaiKH);
            cmd.Parameters.AddWithValue("@ghichu", Ghichu);
            //cmd.ExecuteNonQuery();

            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            str = dt.Rows[0].ItemArray[0].ToString();

            cmd.Dispose();
            con.Close();

            return str;
        }
开发者ID:BachDieuLinh,项目名称:QLSieuThi,代码行数:27,代码来源:KhachHang.cs

示例4: Find

        public Patient Find(long voterId)
        {
            string query = "SELECT * FROM tbl_patient WHERE voter_id='" + voterId + "'";
            ASqlCommand = new SqlCommand(query, ASqlConnection);
            ASqlConnection.Open();
            ASqlDataReader = ASqlCommand.ExecuteReader();

            if (ASqlDataReader.HasRows)
            {
                Patient aPatient = new Patient();
                ASqlDataReader.Read();
                aPatient.Id = (int)ASqlDataReader["id"];
                aPatient.VoterId = (long)ASqlDataReader["voter_id"];

                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return aPatient;
            }
            else
            {
                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return null;
            }
        }
开发者ID:MirajHossain,项目名称:Community-Medicine-System,代码行数:27,代码来源:PatientDBGateway.cs

示例5: methodregister

        public string methodregister(string userid, string firstname, string lastname, string pswrd, string sex, string streeet, string town, string stat, string zipcode, string phonenum, string que, string ans)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("Select * from userinfo where uid = '"+ userid +"'", conn);
            SqlDataReader read = cmd.ExecuteReader();
             if( (read.HasRows))
             {
             cmd.Dispose();
             read.Close();
             conn.Close();
             return "fail";

             }

            else
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1"].ConnectionString);
                con.Open();
                SqlCommand c = new SqlCommand("Insert into userinfo(uid,fname,lname,phone,password,gender,street,city,state,zip,secQ,secAns) values ( '" + userid + "', '" + firstname + "','" + lastname + "','" + phonenum + "','" + pswrd + "', '" + sex + "','" + streeet + "','" + town + "','" + stat + "','" + zipcode + "','" + que + "','" + ans + "')", con);
                int n = c.ExecuteNonQuery();
                cmd.Dispose();
                c.Dispose();
                read.Close();
                con.Close();
                conn.Close();
                return ("success");

             }
        }
开发者ID:smartshopy,项目名称:smartshopy,代码行数:30,代码来源:Registrationservice.asmx.cs

示例6: GetString

 public static string connstring = ConfigurationManager.ConnectionStrings["connid"].ToString(); //ConfigurationManager.AppSettings["connid"];
 public static string GetString(string query)
 {
     string retvalue = "";
     SqlConnection sqlcon = new SqlConnection(connstring);
     SqlCommand sqlcom = new SqlCommand(query, sqlcon);
     //sqlcom.CommandType = CommandType.Text;
     sqlcon.Open();
     SqlDataReader sqldr = sqlcom.ExecuteReader();
     sqldr.Read();
     try
     {
         retvalue = sqldr[0].ToString();
         sqldr.Dispose();
         sqlcom.Dispose();
         sqlcon.Close();
     }
     catch
     {
         sqldr.Dispose();
         sqlcom.Dispose();
         sqlcon.Close();
         return "";
     }
     return retvalue;
 }
开发者ID:pshreez,项目名称:ASP.NET,代码行数:26,代码来源:Class1.cs

示例7: IsValid

 /// <summary>
 /// Checks if user with given password exists in the database
 /// </summary>
 /// <param name="_username">User name</param>
 /// <param name="_password">User password</param>
 /// <returns>True if user exist and password is correct</returns>
 public bool IsValid(string _username, string _password)
 {
     using (var cn = new SqlConnection(@"Data Source=jeff.cedarville.edu; Persist Security Info=True;User ID=itm3500;Password=itm3500; MultipleActiveResultSets=True"))
     {
         string _sql = @"SELECT [Username] FROM [VanDintel-HarrisProject_Security].[System_Users] " +
                @"WHERE [Username] = @u AND [Password] = @p";
         var cmd = new SqlCommand(_sql, cn);
         cmd.Parameters
             .Add(new SqlParameter("@u", SqlDbType.NVarChar))
             .Value = _username;
         cmd.Parameters
             .Add(new SqlParameter("@p", SqlDbType.NVarChar))
             .Value = System.Web.Helpers.Crypto.SHA1(_password);
         cn.Open();
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             reader.Dispose();
             cmd.Dispose();
             return true;
         }
         else
         {
             reader.Dispose();
             cmd.Dispose();
             return false;
         }
     }
 }
开发者ID:vvandintel,项目名称:BookSiteRepository,代码行数:35,代码来源:User.cs

示例8: IsValid

        public bool IsValid(string _username, string _password)
        {
            string npiconstring = ConfigurationManager.ConnectionStrings["npi_con_string"].ConnectionString;

            using (var cs = new SqlConnection(npiconstring))
            {
               string _sql = @"SELECT [username] FROM [dbo].[System_Users]" + @"WHERE [username] = @u AND [password]= @p";
               //Ejecutar comando
               var cmd = new SqlCommand(_sql, cs);
               cmd.Parameters
                   .Add(new SqlParameter("@u", SqlDbType.NVarChar))
                   .Value = _username;
               cmd.Parameters
                   .Add(new SqlParameter("@p", SqlDbType.NVarChar))
                   //.Value = Helpers.SHA1.Encode(_password); <--- Verificar porque no esta agarrando el encoding
                   .Value = _password;
               //Abrir conexion
               cs.Open();
               //Leer datos
               var reader = cmd.ExecuteReader();
               if (reader.HasRows)
               {
                   reader.Dispose();
                   cmd.Dispose();
                   return true;
               }

               else
               {
                   reader.Dispose();
                   cmd.Dispose();
                   return false;
               }
            }
        }
开发者ID:payucon5103,项目名称:DevHaven,代码行数:35,代码来源:User.cs

示例9: Find

        public Medicine Find(string name)
        {
            string query = "SELECT * FROM tbl_medicine WHERE name='" + name + "'";
            ASqlCommand = new SqlCommand(query, ASqlConnection);
            ASqlConnection.Open();
            ASqlDataReader = ASqlCommand.ExecuteReader();

            if (ASqlDataReader.HasRows)
            {
                Medicine aMedicine = new Medicine();
                ASqlDataReader.Read();
                aMedicine.Id = (int)ASqlDataReader["id"];
                aMedicine.Name = ASqlDataReader["name"].ToString();
                aMedicine.Power = Convert.ToDecimal(ASqlDataReader["power"]);
                aMedicine.Type = ASqlDataReader["type"].ToString();

                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return aMedicine;
            }
            else
            {
                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return null;
            }
        }
开发者ID:MirajHossain,项目名称:Community-Medicine-System,代码行数:29,代码来源:MedicineDBGateway.cs

示例10: LinkAbsenceWithLeaveRequest

        public void LinkAbsenceWithLeaveRequest(List<ReportedAbsenceEntity> t, LeaveRequestEntity request)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;

            try
            {
                conn = DALHelper.CreateSqlDbConnection();

                foreach (ReportedAbsenceEntity ae in t)
                {
                    cmd = new SqlCommand("usp_LinkAbsenceWithLeaveRequest", conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@ReportedAbsenceId", ae.Id);
                    cmd.Parameters.AddWithValue("@LeaveRequestId", request.Id);

                    conn.Close();
                    cmd.Dispose();

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
开发者ID:GramozKrasniqi,项目名称:HRMS,代码行数:34,代码来源:ReportedAbsenceMapper.cs

示例11: IsValid

 /// <summary>
 /// Checks if user with given password exists in the database
 /// </summary>
 /// <param name="_username">User name</param>
 /// <param name="_password">User password</param>
 /// <returns>True if user exist and password is correct</returns>
 public bool IsValid(string _username, string _password)
 {
     using (var cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename" +
       @"='C:\Tutorials\1 - Creating a custom user login form\Creating " +
       @"a custom user login form\App_Data\Database1.mdf';Integrated Security=True"))
     {
         string _sql = @"SELECT [Username] FROM [dbo].[System_Users] " +
                @"WHERE [Username] = @u AND [Password] = @p";
         var cmd = new SqlCommand(_sql, cn);
         cmd.Parameters
             .Add(new SqlParameter("@u", SqlDbType.NVarChar))
             .Value = _username;
         cmd.Parameters
             .Add(new SqlParameter("@p", SqlDbType.NVarChar))
             .Value = Helpers.SHA1.Encode(_password);
         cn.Open();
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             reader.Dispose();
             cmd.Dispose();
             return true;
         }
         else
         {
             reader.Dispose();
             cmd.Dispose();
             return false;
         }
     }
 }
开发者ID:AleksandarP91,项目名称:MVC,代码行数:37,代码来源:User.cs

示例12: FindDistrict

        public District FindDistrict(string name)
        {
            string query = "SELECT * FROM tbl_district WHERE name='" + name + "'";
            ASqlCommand = new SqlCommand(query, ASqlConnection);
            ASqlConnection.Open();
            ASqlDataReader = ASqlCommand.ExecuteReader();

            if (ASqlDataReader.HasRows)
            {
                District aDistrict = new District();
                ASqlDataReader.Read();
                aDistrict.Id = (int) ASqlDataReader["id"];
                aDistrict.Name = ASqlDataReader["name"].ToString();
                aDistrict.Population = (int) ASqlDataReader["population"];

                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return aDistrict;
            }
            else
            {
                ASqlDataReader.Close();
                ASqlCommand.Dispose();
                ASqlConnection.Close();
                return null;
            }
        }
开发者ID:MirajHossain,项目名称:Community-Medicine-System,代码行数:28,代码来源:DistrictAndThanaDBGateway.cs

示例13: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            if (!String.IsNullOrEmpty(context.Request.QueryString["term"].ToString()))
            {
                string connStr = ConfigurationManager.ConnectionStrings["DBCONNSTRING"].ToString();
                SqlConnection sqlconn = new SqlConnection(connStr);
                SqlCommand sqlcmd = new SqlCommand();

                try
                {
                    if (sqlconn.State == ConnectionState.Closed)
                    {
                        sqlconn.Open();
                    }

                    sqlcmd.Connection = sqlconn;
                    sqlcmd.CommandType = CommandType.Text;
                    sqlcmd.CommandText = "SELECT top 10 x.CountryName as cn FROM Countries as x WHERE x.CountryName LIKE '%' + @cn + '%'";
                    sqlcmd.Parameters.AddWithValue("@cn", context.Request.QueryString["term"].ToString());

                    sqlcmd.ExecuteNonQuery();

                    SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        string[] items = new string[dt.Rows.Count];
                        int ctr = 0;
                        foreach (DataRow row in dt.Rows)
                        {
                            items[ctr] = (string)row["cn"];
                            ctr++;
                        }

                        //convert the string array to Javascript and send it out
                        context.Response.Write(new JavaScriptSerializer().Serialize(items));
                    }
                    if (sqlconn.State == ConnectionState.Open)
                    {
                        sqlcmd.Dispose();
                        sqlconn.Close();
                        sqlconn.Dispose();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (sqlconn.State == ConnectionState.Open)
                    {
                        sqlcmd.Dispose();
                        sqlconn.Close();
                        sqlconn.Close();
                    }
                }
            }
        }
开发者ID:zgying,项目名称:CRMWeiXin,代码行数:60,代码来源:Search.ashx.cs

示例14: log

    public string log(string uname, string pwd)
    {
        //if (uname == "admin" && pwd == "admin")
        //{
        //    return "success";
        //}
        //else
        //{
        //    return "fail";
        //}

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbString"].ConnectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand("Select * from Table2 where Userid='" + uname + "' AND Password = '" + pwd + "' ", conn);
        SqlDataReader data = null;
        data = cmd.ExecuteReader();
        if (data.HasRows)
        {
            data.Dispose();
            cmd.Dispose();
            conn.Close(); return "Y";
        }
        else
        {
            data.Dispose();
            cmd.Dispose();
            conn.Close(); return "N";
        }
    }
开发者ID:anoopjavvadi,项目名称:Blood-Donor-Explorer,代码行数:29,代码来源:Ls.cs

示例15: ExecuteMyQuery

    public static void ExecuteMyQuery(string Query)
    {
        string conString = System.Configuration.ConfigurationManager.ConnectionStrings["constrww"].ToString();
        SqlConnection Connection = new SqlConnection(conString);
        Connection.Open();
        SqlCommand cmdXls = new SqlCommand(Query, Connection);

        try
        {
            cmdXls.ExecuteNonQuery();
        }
        catch (Exception e)
        {

            cmdXls.Dispose();

            Connection.Dispose();
        }
        finally
        {

            cmdXls.Dispose();

            Connection.Dispose();

        }
    }
开发者ID:websnipe-abhik,项目名称:Subpoena,代码行数:27,代码来源:DbConnectionController.cs


注:本文中的System.Data.SqlClient.SqlCommand.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。