private void button1_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count != 0) { for (int q = 0; q < dataGridView1.Rows.Count; q++) { if (dataGridView1.Rows[q].Cells[q].Value.ToString() == textBox1.Text)//ถ้าซ้ำ { MessageBox.Show("abc"); } else { string strConn = "Data Source = localhost;" + "Initial Catalog = Books; " + "Integrated Security = SSPI;"; SqlConnection conn = new SqlConnection(strConn); if (conn.State == ConnectionState.Closed) { conn.Open(); } else { conn.Close(); conn.Open(); } SqlCommand cmd = conn.CreateCommand(); string sqlstatement = "select * from Books where idb='" + textBox1.Text + "'"; cmd.CommandType = CommandType.Text; cmd.CommandText = sqlstatement; SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { int i = 0, j = 1, l = 2; while (reader.Read()) { string idb = reader[0].ToString(); string names = reader[1].ToString(); string price = reader[2].ToString(); double to = Convert.ToInt32(price); double per = (to * 10) / 100; dataGridView1.Rows.Add(); dataGridView1.Rows[k].Cells[i].Value = idb; dataGridView1.Rows[k].Cells[j].Value = names; dataGridView1.Rows[k].Cells[l].Value = price; i++; j++; l++; k++; } } else { MessageBox.Show("!!!ไม่มีรหัสหนังสือนี้!!!", "ข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information); } conn.Close(); } } } }
if (dataGridView1.Rows.Count != 0) { for (int q = 0; q < dataGridView1.Rows.Count; q++) { int w = 0; if (dataGridView1.Rows[q].Cells[w].Value == textBox1)//ถ้าซ้ำ { MessageBox.Show("ซ้ำ"); } else //ถ้าไม่ซ้ำ { // ข้อมูล } } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง