using System.Data.SqlClient;
private void button1_Click(object sender, EventArgs e)
{
//to read from DB
string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Thisal Lekamge\Desktop\Shohan\new\ChainMan.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(" select * from Item ", connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
MessageBox.Show(reader["itemName"].ToString());
MessageBox.Show(reader["itemDescription"].ToString());
}
}
reader.Close();
}
connection.Close();
}
}
No comments:
Post a Comment