Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Configuration;
  10. using System.Data.SqlClient;
  11.  
  12. namespace Sample01
  13. {
  14. public partial class FrmSyohinSyokai : Form
  15. {
  16. public FrmSyohinSyokai()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void btnHyouji_Click(object sender, EventArgs e)
  22. {
  23. string connectionString = ConfigurationManager.ConnectionStrings["Db"].ConnectionString;
  24. using (SqlConnection connection = new SqlConnection(connectionString))
  25. {
  26. string sql = "select * from syohin";
  27. SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
  28. DataSet dataSet = new DataSet();
  29. adapter.Fill(dataSet, "syohin");
  30. DataTable dataTable = dataSet.Tables["syohin"];
  31. dgvSyohin.DataSource = dataTable;
  32. }
  33. }
  34.  
  35. private void btnReset_Click(object sender, EventArgs e)
  36. {
  37. dgvSyohin.DataSource = null;
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement