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.Data.SqlClient; namespace BusOnline { public partial class Form3 : Form { DataSet ds; SqlCommand cmd; SqlDataAdapter adp; SqlConnection conn; public Form3() { InitializeComponent(); } private void Form3_Load(object sender, EventArgs e) { OpenConnectionDatabase(); conn.Close(); } private void OpenConnectionDatabase() { string conStr = @"data source =.\sqlexpress;attachDbFilename = D:\Project\BusDB\db.mdf;"; conStr += "Integrated Security = True;"; conn = new SqlConnection(conStr); open_conn(); clearData(); } private void clearData() { textBox1.Text = ""; textBox2.Text = ""; } private void open_conn() { if (conn.State == ConnectionState.Closed) conn.Open(); } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (textBox1.Text.Trim() == "") { return; } if (e.KeyCode == Keys.Enter) { string sql = "select cuscode from customer where cuscode = @cusc"; cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.CommandText = sql; cmd.Parameters.Clear(); cmd.Parameters.Add("@cusc", SqlDbType.NChar).Value = textBox1.Text.Trim(); adp = new SqlDataAdapter(cmd); ds = new DataSet(); int p = adp.Fill(ds,"cus"); if (p > 0) { textBox2.Text = ds.Tables["cus"].Rows[0]["cusc"].ToString(); textBox1.Focus(); } else { MessageBox.Show("Identify not found"); clearData(); } } } private void button2_Click(object sender, EventArgs e) { this.Hide(); FormMenuMain f = new FormMenuMain(); f.Show(); } private void button1_Click_1(object sender, EventArgs e) { if (textBox1.Text == textBox2.Text && textBox1.Text.Length > 0) { this.Hide(); FormSub2 f = new FormSub2(); f.Show(); } else { MessageBox.Show("Identify not compare"); clearData(); } } } }
cmd.connection = conn;
Quote:OpenConnectionDatabase(); conn.Close();
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง