Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Configuration;
- using System.Data.SqlClient;
- namespace Sample02
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnHyouji_Click(object sender, EventArgs e)
- {
- string connectionString = ConfigurationManager.ConnectionStrings["Db"].ConnectionString;
- using (SqlConnection connection = new SqlConnection(connectionString))
- {
- string sql = "select * from syohin where syohincode = @syohincode";
- SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
- adapter.SelectCommand.Parameters.Add("@syohincode", SqlDbType.Char);
- adapter.SelectCommand.Parameters["@syohincode"].Value = txtSyohinCode.Text;
- DataSet dataSet = new DataSet();
- int cnt = adapter.Fill(dataSet, "syohin");
- if (cnt != 0)
- {
- DataTable dataTable = dataSet.Tables["syohin"];
- txtSyohinName.Text = dataTable.Rows[0]["syohinname"].ToString();
- txtPrice.Text = ((int)dataTable.Rows[0]["price"]).ToString("c");
- txtBunrui.Text = dataTable.Rows[0]["bunruino"].ToString();
- }
- else
- {
- txtSyohinName.Text = "";
- txtPrice.Text = "";
- txtBunrui.Text = "";
- MessageBox.Show("該当商品なし", "検索エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement