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 Project { public partial class Insertmain : Form { public Insertmain() { InitializeComponent(); } private SqlConnection connection; private SqlCommand command; private string sql; private void Insertmain_Load(object sender, EventArgs e) { string conStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataPro.mdf;Integrated Security=True;User Instance=True;"; connection = new SqlConnection(conStr); connection.Open(); sql = "SELECT type_id as max FROM workunit_type"; command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet data = new DataSet(); adapter.Fill(data, "ty"); int numRow = data.Tables["ty"].Rows.Count; numRow = numRow + 1; string numRow2 = Convert.ToString(numRow); numRow2 = "wt0" + numRow2; textBox2.Text = numRow2; } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { this.Close(); Workloadmain workmi = new Workloadmain(); workmi.Show(); connection.Close(); } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "") { sql = "insert into workunit_type values(@user,@pass)"; //command = new SqlCommand(sql, connection); command.CommandText = sql; command.Parameters.AddWithValue("user", textBox2.Text); command.Parameters.AddWithValue("pass", textBox1.Text); int r = command.ExecuteNonQuery(); if (r > 0) { MessageBox.Show(textBox2.Text); MessageBox.Show(textBox1.Text); Close(); Workloadmain workmi = new Workloadmain(); workmi.Show(); connection.Close(); } else { MessageBox.Show("เกิดความผิดพลาด กรุณาลองใหม่"); Close(); } } } } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง