本文整理汇总了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();
}
}
示例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();
}
示例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();
}
}
示例4: LiberarDataReader
protected void LiberarDataReader(ref SqlDataReader oDataReader)
{
if (oDataReader != null)
oDataReader.Dispose();
oDataReader = null;
}
示例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;
}
示例6: DataReaderClose
/// <summary>
/// 关闭DataReade
/// </summary>
/// <param name="reader">参数1:SqlDataReader</param>
public static void DataReaderClose(SqlDataReader reader)
{
if (reader != null)
{
reader.Dispose();
reader.Close();
}
}
示例7: cargarListBox
public static void cargarListBox(ListBox unListBox, SqlDataReader reader)
{
while (reader.Read())
{
unListBox.Items.Add(reader.GetSqlString(0));
}
reader.Dispose();
}
示例8: cargarComboBox
public static void cargarComboBox(ComboBox unCombo,SqlDataReader reader)
{
while (reader.Read())
{
unCombo.Items.Add(reader.GetSqlString(0));
}
reader.Dispose();
}
示例9: closeDataReader
///<summary>
///关闭datareader
///传入SqlDataReader的ref
///</summary>
public static void closeDataReader(ref SqlDataReader sdr)
{
try
{
sdr.Close();
sdr.Dispose();
}
catch (Exception)
{ }
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
}
示例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();
}