OKIEWARDOYO

C#.NET No.38 - 2

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