Sunday, July 8, 2012
Retrieve Data from a Database ( Data Adapter / Data Reader) without using a DataGridView
//using System.Data.SqlClient; //header
using (SqlConnection connection = new SqlConnection(Trial.Program.Globals.db.connectionString))
using (SqlCommand command = new SqlCommand(" select itemName from Item ", connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
listBox1.Items.Add(reader["itemName"].ToString());
}
}
reader.Close();
}
connection.Close();
}
here you can use a data reader(SqlDataReader) instead of using a data adapter(SqlDataAdapter).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment