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


C# SqlDataReader.Dispose方法代码示例

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


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

示例1: Name_TextChanged

 private void Name_TextChanged(object sender, EventArgs e)
 {
     myConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True;User Instance=True");
     myConn.Open();
     string commandString = @"SELECT * FROM Asset WHERE [Asset Name] = '" + name.Text + "'";
     SqlCommand cmd = new SqlCommand(commandString, myConn);
     rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         if (rdr != null)
         {
             rdr.Dispose();
         }
     SqlDataAdapter adapter = new SqlDataAdapter(@"SELECT Asset.[Asset ID], Asset.[Asset Name], Asset.[Asset Category], Category.[Category Type], Status.[Status] , History.* FROM Asset JOIN History ON Asset.[Asset ID] = History.[Asset ID] JOIN Status ON Status.[Status ID] = Asset.[Asset Status] JOIN Category ON Category.[Category ID] = Asset.[Asset Category] WHERE [Asset Name]  = '"+ name.Text+ "'", myConn);
     DataTable t = new DataTable();
     adapter.Fill(t);
     t.Columns.RemoveAt(5);
     t.Columns.RemoveAt(10);
     dataGridView1.DataSource = t;
     dataGridView1.Columns[2].Visible = false;
     this.dataGridView1.Columns[8].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     dataGridView1.Refresh();
     myConn.Close();
     }
     else
     {
         MessageBox.Show("Not in database!!");
         this.Dispose();
     }
 }
开发者ID:ralphachua,项目名称:FixedAssetManagementSystem,代码行数:30,代码来源:ByName.cs

示例2: Listar_Click

        protected void Listar_Click(object sender, EventArgs e)
        {
            string nome;
            int idBusca;

            ListaNomes.Items.Clear();

            if(int.TryParse(textID.Text, out idBusca) == false)
            {
                lblMensagem.Text = "Campo de busca ID em branco..!";
                return;
            }

            conn.Open();
            command = new SqlCommand("SELECT Id, Nome FROM tbPessoa WHERE Id >= @a", conn);
            command.Parameters.AddWithValue("@a", idBusca);
            reader = command.ExecuteReader();

            while(reader.Read())
            {
                idBusca = reader.GetInt32(0);
                nome = reader.GetString(1);
                ListItem item = new ListItem(nome, Convert.ToString(idBusca));
                ListaNomes.Items.Add(item);
            }

            reader.Close();
            reader.Dispose();
            command.Dispose();
            conn.Close();
            conn.Dispose();
        }
开发者ID:Raffaferreira,项目名称:ProgramacaoWEB2015,代码行数:32,代码来源:WebForm2.aspx.cs

示例3: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                conn.Open();
                command = new SqlCommand("SELECT Nome, Id FROM tbAluno", conn);
                reader = command.ExecuteReader();

                string Nome;
                int valor;

                while (reader.Read())
                {
                    Nome = reader.GetString(0);
                    valor = reader.GetInt32(1);
                    ListItem item = new ListItem(Nome, Convert.ToString(valor));
                    DropListNomes.Items.Add(item);
                }

                reader.Close();
                reader.Dispose();
                command.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
开发者ID:Raffaferreira,项目名称:ProgramacaoWEB2015,代码行数:26,代码来源:WebForm1.aspx.cs

示例4: LiberarDataReader

        protected void LiberarDataReader(ref SqlDataReader oDataReader)
        {
            if (oDataReader != null)
                oDataReader.Dispose();

            oDataReader = null;
        }
开发者ID:castrorodrigo355,项目名称:PagoElectronico,代码行数:7,代码来源:BaseDALC.cs

示例5: ConvertDataReaderToDataTable

 /// <summary>
 /// ��DataReader תΪ DataTable
 /// </summary>
 /// <param name="DataReader">DataReader</param>
 public DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
 {
     DataTable datatable = new DataTable();
     try
     {
         DataTable schemaTable = dataReader.GetSchemaTable();
         //��̬�����
         foreach (DataRow myRow in schemaTable.Rows)
         {
             DataColumn myDataColumn = new DataColumn();
             myDataColumn.DataType = System.Type.GetType("System.String");
             myDataColumn.ColumnName = myRow[0].ToString();
             datatable.Columns.Add(myDataColumn);
         }
         //�������
         while (dataReader.Read())
         {
             DataRow myDataRow = datatable.NewRow();
             for (int i = 0; i < schemaTable.Rows.Count; i++)
             {
                 myDataRow[i] = dataReader[i].ToString();
             }
             datatable.Rows.Add(myDataRow);
             myDataRow = null;
         }
         schemaTable = null;
     }
     finally
     {
         dataReader.Close();
         dataReader.Dispose();
     }
     return datatable;
 }
开发者ID:blfsir,项目名称:benzoa,代码行数:38,代码来源:ControlPositionTreeView.ascx.cs

示例6: DataReaderClose

 /// <summary>
 /// 关闭DataReade
 /// </summary>
 /// <param name="reader">参数1:SqlDataReader</param>
 public static void DataReaderClose(SqlDataReader reader)
 {
     if (reader != null)
     {
         reader.Dispose();
         reader.Close();
     }
 }
开发者ID:SaintLoong,项目名称:LifeFramwork,代码行数:12,代码来源:SqlHelper.cs

示例7: cargarListBox

 public static void cargarListBox(ListBox unListBox, SqlDataReader reader)
 {
     while (reader.Read())
     {
         unListBox.Items.Add(reader.GetSqlString(0));
     }
     reader.Dispose();
 }
开发者ID:martinnbasile,项目名称:aerolineaFRBA,代码行数:8,代码来源:CargadorDeEstructura.cs

示例8: cargarComboBox

 public static void cargarComboBox(ComboBox unCombo,SqlDataReader reader)
 {
     while (reader.Read())
     {
         unCombo.Items.Add(reader.GetSqlString(0));
     }
     reader.Dispose();
 }
开发者ID:martinnbasile,项目名称:aerolineaFRBA,代码行数:8,代码来源:CargadorDeEstructura.cs

示例9: closeDataReader

 ///<summary>
 ///关闭datareader
 ///传入SqlDataReader的ref
 ///</summary>
 public static void closeDataReader(ref SqlDataReader sdr)
 {
     try
     {
         sdr.Close();
         sdr.Dispose();
     }
     catch (Exception)
     { }
 }
开发者ID:elfmedy,项目名称:2013,代码行数:14,代码来源:MyFunction.cs

示例10: id_TextChanged

        private void id_TextChanged(object sender, EventArgs e)
        {
            myConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True;User Instance=True");
            myConn.Open();

            string commandString = @"SELECT * FROM Asset WHERE [Asset ID] = '" + id.Text + "'";
            SqlCommand cmd = new SqlCommand(commandString, myConn);
            string commandString1 = "";
            rdr = cmd.ExecuteReader();
            if (rdr.HasRows)
            {
                while (rdr.Read())
                {

                    name.Text = (string)rdr["Asset Name"];
                    ACost.Text = rdr["Asset Acquisition Cost"].ToString();
                    Life.Text = rdr["Asset Useful Life"].ToString();
                    commandString = @"SELECT [Status] FROM Status WHERE [Status ID] like '" + rdr["Asset Status"] + "'";

                    commandString1 = @"SELECT [Category Type] FROM Category WHERE [Category ID] = " + rdr["Asset Category"];

                }
                if (rdr != null)
                {
                    rdr.Dispose();
                }
                 cmd = new SqlCommand(commandString, myConn);
                  stat.Text = (string)cmd.ExecuteScalar();

                cmd = new SqlCommand(commandString1, myConn);
                category.Text = (string)cmd.ExecuteScalar();
                commandString = @"SELECT CASE WHEN (CAST([Asset Acquisition Cost] - [Asset Acquisition Cost]/[Asset Useful Life] *  DATEDIFF(year, [Asset Purchase Date], GETDATE() ) as Decimal(12 , 2)) <= 0) THEN [Quantity] ELSE CAST([Asset Acquisition Cost] - [Asset Acquisition Cost]/[Asset Useful Life] *  DATEDIFF(year, [Asset Purchase Date], GETDATE() ) as Decimal(12 , 2)) END  From Asset Where [Asset ID] ='" + id.Text + "'";
                cmd = new SqlCommand(commandString, myConn);
                BookVal.Text = cmd.ExecuteScalar().ToString();

                //SqlDataAdapter adapter = new SqlDataAdapter(@"SELECT ([Asset Acquisition Cost] - [Depreciation Years]) AS [Test]  From Asset Join Category ON Asset.[Asset Category] = Category.[Category ID] Where [Asset ID] =" + id.Text, myConn);
                SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM History WHERE [Asset ID] = '" + id.Text + "'", myConn);
                DataTable t = new DataTable();
                adapter.Fill(t);
                dataGridView1.DataSource = t;
                this.dataGridView1.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }
            else
            {
                MessageBox.Show("Not in database!!");
                this.Dispose();
            }
            myConn.Close();
        }
开发者ID:ralphachua,项目名称:FixedAssetManagementSystem,代码行数:49,代码来源:Output.cs

示例11: lay1dong

        public string lay1dong(string sql)
        {
            connect();
            cm = new SqlCommand(sql, con);


            reader = cm.ExecuteReader();
            string v = reader.Read() ? reader[0].ToString() : "";
            reader.Dispose();


            connectClose();
            return v;

        }
开发者ID:ngocson0012,项目名称:FaceSon,代码行数:15,代码来源:ketnoi.cs

示例12: getdata

 private void getdata()
 {
     cmd = new SqlCommand("select * from HOCSINH", conn);
     dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         var masv = (string)dr["MAHS"];
         var hoten = (string)dr["HOTEN"];
         var ngaysinh = dr["NGAYSINH"];
         var quequan = (string)dr["QUEQUAN"];
         var makhoa = (string)dr["MALOP"];
         dataGridView1.Rows.Add(masv, hoten, ngaysinh.ToString(), quequan, makhoa);
     }
     dr.Close();
     dr.Dispose();
 }
开发者ID:manhhue218922694,项目名称:QLKhachSan_TTNhom,代码行数:16,代码来源:Form1.cs

示例13: TransformaReaderEmLista

 private List<TransportadorEmpresa> TransformaReaderEmLista(SqlDataReader reader)
 {
     var transportador = new List<TransportadorEmpresa>();
     while (reader.Read())
     {
         var temObjeto = new TransportadorEmpresa
         {
             IdTransportador = int.Parse(reader["IDTRANSPORTADOR"].ToString()),
             Nome = reader["NOME_TRANSPORTADOR"].ToString()
         };
         transportador.Add(temObjeto);
     }
     reader.Close();
     reader.Dispose();
     return transportador;
 }
开发者ID:WellingtonJJ,项目名称:.Net,代码行数:16,代码来源:VeiculoAplicacao.cs

示例14: AdminNameFetch

    public String AdminNameFetch(int admin_id)
    {
        String AdminName = "";

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

            String query = "Select first_name,last_name from admin_info where admin_id = @aid";
            command = new SqlCommand(query, newcon);
            command.Parameters.AddWithValue("@aid", admin_id);

            reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                {
                    AdminName = reader[0].ToString() + " " + reader[1].ToString();
                }
            }
            else
            {
                AdminName = "";
            }

            command.Dispose();
            reader.Dispose();

            return AdminName;
        }

        catch
        {
            throw;
        }
        finally
        {
            if (newcon.State == ConnectionState.Open)
            {
                newcon.Close();
            }
        }
    }
开发者ID:rajarupinder,项目名称:HIT,代码行数:47,代码来源:UserFunctionsDAL.cs

示例15: ShowDatabase

 public void ShowDatabase()
 {
     ChuoiConnect = @"Data Source=.\SQLEXpress;Integrated Security=True";
     Conn = new SqlConnection(ChuoiConnect);
     Conn.Open();
     //sql="EXEC sp_databases";
     sql = "SELECT * FROM sys.databases d WHERE d.database_id>4";
     Cmd = new SqlCommand(sql, Conn);
     Reader = Cmd.ExecuteReader();
     cbo_database.Items.Clear();
     while(Reader.Read())
     {
         cbo_database.Items.Add(Reader[0].ToString());
     }
     Reader.Dispose();
     Conn.Close();
     Conn.Dispose();
 }
开发者ID:MHHHK1,项目名称:Karaoke,代码行数:18,代码来源:Frm_SaoLuuDuLieu.cs


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