Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 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 Ensyu01
  13. {
  14. public partial class FrmSyohinKensaku : Form
  15. {
  16. public FrmSyohinKensaku()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void btnKensaku_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 SyohinCode,SyohinName,Price,BunruiName from syohin inner join Bunrui on syohin.BunruiNo = Bunrui.BunruiNo where SyohinName LIKE @sname";
  27.  
  28. SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
  29. adapter.SelectCommand.Parameters.Add("@sname", SqlDbType.NVarChar);
  30. adapter.SelectCommand.Parameters["@sname"].Value = "%" + txtSyohinName.Text + "%";
  31.  
  32. DataSet dataSet = new DataSet();
  33. adapter.Fill(dataSet, "syohin");
  34. DataTable dataTable = dataSet.Tables["syohin"];
  35.  
  36. dvgSyohin.DataSource = dataTable;
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement