WPF C# using

索引サイト
普通に動作する場合

意味不明なまま動作不能(注釈部が必要)

using を使用しない場合-->モジュール内共有の例




public partial class Window1 : Window
{
System.Data.Odbc.OdbcConnection z_DB = new System.Data.Odbc.OdbcConnection();
System.Data.Odbc.OdbcCommand z_CMD = new System.Data.Odbc.OdbcCommand();

public Window1()
{
InitializeComponent();

Public_DSN w_DSN = new Public_DSN();
z_DB.ConnectionString = w_DSN.name;
z_CMD.Connection = z_DB;

z_DB.Open();

read_hinmei();

this.Left = 100;
this.Top = 100;
}
private void read_hinmei()
{
Public_Shohin w_shohin = new Public_Shohin();
string w_hinmei = w_shohin.name;
this.textBlock_name.Text = w_hinmei;

z_CMD.CommandText = "select * from tb_hinmei";
z_CMD.CommandText += " where name_shohin = '" + w_hinmei + "'";
System.Data.Odbc.OdbcDataReader w_reader = z_CMD.ExecuteReader();

while (w_reader.Read())
{
this.textBlock_code.Text = Convert.ToString(w_reader["code_shohin"]);
Double w_change_case = Convert.ToDouble(w_reader["change_case"]);
Double w_change_ton = Convert.ToDouble(w_reader["change_ton"]);
this.textBox_case.Text = w_change_case.ToString("#,0.0");
this.textBox_ton.Text = w_change_ton.ToString("#,0.0");
}
w_reader.Close();
}
private void button_update_Click(object sender, RoutedEventArgs e)
{
update();
}
//*************************************************
// 更新
//*************************************************
private void update()
{
string w_code = this.textBlock_code.Text;
string w_name = this.textBlock_name.Text;
double w_case = Convert.ToDouble(this.textBox_case.Text);
double w_ton = Convert.ToDouble(this.textBox_ton.Text);

z_CMD.CommandText = "update tb_hinmei set change_case = " + w_case + ",change_ton = " + w_ton;
z_CMD.CommandText += " where name_shohin = '" + w_name + "'";
try
{
z_CMD.ExecuteNonQuery();
MessageBox.Show("更新されました。");
}
catch
{
z_CMD.ExecuteNonQuery();
MessageBox.Show("エラー・・更新できませんでした。");
}
this.Close();
}
}




public class Public_Shohin
{
static string m_code;
public string code
{
set { m_code = value; }
get { return m_code; }
}
static string m_name;
public string name
{
set { m_name = value; }
get { return m_name; }
}
}
public class Public_DSN
{
static string m_DSN;
public string name
{
get { return m_DSN; }
set { m_DSN = value; }
}
}




AX