Skip to content

Instantly share code, notes, and snippets.

@tedliou
Last active April 6, 2016 15:27
Show Gist options
  • Save tedliou/5273bf9c52645032c711 to your computer and use it in GitHub Desktop.
Save tedliou/5273bf9c52645032c711 to your computer and use it in GitHub Desktop.
SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand("select * from [Table]", sql);
sql.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
listView1.Items.Insert(0, reader[0].ToString());
listView1.Items[0].SubItems.Add(reader[1].ToString());
}
}
reader.Close();
sql.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment