OKIEWARDOYO

C#.NET No.38

Feb 4th, 2014
14,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. private void LoadingData()
  2.         {
  3.  
  4.             string connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=ContohLocalDb.mdf;Integrated Security=True";
  5.  
  6.             try
  7.             {
  8.                 SqlConnection connection = new SqlConnection(connString);
  9.                 connection.Open();
  10.  
  11.                 Console.WriteLine("State: {0}", connection.State);
  12.                 Console.WriteLine("ConnectionString: {0}", connection.ConnectionString);
  13.                 MessageBox.Show("Sip, konek kang");
  14.  
  15.                 SqlCommand command = new SqlCommand("SELECT * FROM TableLagu", connection);
  16.                 SqlDataAdapter adapter = new SqlDataAdapter(command);
  17.  
  18.                 DataTable table = new DataTable();
  19.  
  20.                 adapter.Fill(table);
  21.  
  22.                 dataGridView1.DataSource = table;
  23.  
  24.             }
  25.             catch (Exception ex)
  26.             {
  27.                 Console.WriteLine("Failed to Connect::" + ex.Message);
  28.                 MessageBox.Show("Wah, erro bro");
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment