 |
|
กลับมาอีกเเล้วครับ ถามเรื่องการนับเเถวที่เลือกจาก DataGridView1 ก่อนเพิ่มค่าลงใน DataGridView2 ครับ |
|
 |
|
|
 |
 |
|
เอา If คลอบไว้
Code (VB.NET)
If DataGridView1.Rows.Count > (ExecuteScalar จาก db)
'Add DataGridView2.
Else
'Do something.
End if
|
 |
 |
 |
 |
Date :
2010-02-16 15:14:44 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ครับ tungman ไม่เข้าใจตรงนี้ครับ (ExecuteScalar จาก db) คืออะไรหรอครับ
|
 |
 |
 |
 |
Date :
2010-02-16 21:49:39 |
By :
artcode |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะ Sum จำนวนวัคซีนจาก DB ไม่ใช่หรือ ก็ใช้ ExecuteScalar ไง จะได้ query ออกมาเป็น value เลย
|
 |
 |
 |
 |
Date :
2010-02-17 08:08:28 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ tungman มากครับ
เเล้วถ้าผมอยากจะเปลี่ยนเป็นเอาค่าลง DataSet ก่อนเเล้วนับเเถวใน DataSet อะครับ
จะเขียนได้เเบบไหนครับ เพราะตอนนี้เขียนเเบบ วน Add ทีละเเถวที่เลือกเลยอะครับ
Code (VB.NET)
If DataGridView1.Rows(i).Selected Then
Dim j As Integer = Care.DataGridView2.Rows.Add() 'สร้างตัวแปร j ไว้รับค่าที่เราเลือกจาก DataGridView1
Care.DataGridView2.Rows(j).Cells(0).Value = DataGridView1.Rows(i).Cells(0).Value 'คือ ส่งค่าที่เราเลือกจาก DataGridView1 ของ i ไปให้ DataGridView1 ของ j
Care.DataGridView2.Rows(j).Cells(1).Value = DataGridView1.Rows(i).Cells(1).Value
Care.DataGridView2.Rows(j).Cells(2).Value = DataGridView1.Rows(i).Cells(2).Value
Care.DataGridView2.Rows(j).Cells(3).Value = DataGridView1.Rows(i).Cells(3).Value
Care.DataGridView2.Rows(j).Cells(4).Value = DataGridView1.Rows(i).Cells(4).Value
Care.DataGridView2.Rows(j).Cells(5).Value = DataGridView1.Rows(i).Cells(5).Value
Care.DataGridView2.Rows(j).Cells(6).Value = DataGridView1.Rows(i).Cells(6).Value
End If
|
 |
 |
 |
 |
Date :
2010-02-17 12:50:36 |
By :
artcode |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นับแถว datagridview
DataGridView2.Rows.Count
นับแถว dataset
DataSet.Tables["tablename"].Rows.Count
|
 |
 |
 |
 |
Date :
2010-02-17 13:31:46 |
By :
numenoy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณเพื่อน..ลองดูอันนี้ โค้ดส่วนตรวจสอบการลบ ของกวางดึงค่าจาก DB ลง dataset ก่อน
Code (VB.NET)
Dim da = New SqlDataAdapter("SELECT EmpCode,EmpRcode,Rcode,DCode FROM Purchase_Order,Receipt,Distribute WHERE EmpCode = '" & tb_ID.Text & "' or EmpRCode = '" & tb_ID.Text & "' or RCode = '" & tb_ID.Text & "' or DCode = '" & tb_ID.Text & "'", SqlConnection1)
da.Fill(ds, "eid")
Dt = ds.Tables("eid")
If ds.Tables("eid").Rows.Count <> 0 Then
temp_mycommand = "Update employee set Status = '0' where EmpID = '" & tb_ID.Text & "'"
Else
temp_mycommand = "Delete from employee where EmpID ='" & tb_ID.Text & "'"
End If
ยังไงก็แวะกระทู้กวางบ้างนะโน้ต กวางยังไม่ได้เลย
รบกวนพี่ ๆ ด้วยนะคะ T^T (แอบโปรโมทที่ตัวเองถามไว้ เพราะตอนนี้นิ่งสนิทเลยค่ะแก้ไม่ได้)
https://www.thaicreate.com/dotnet/forum/038709.html
|
 |
 |
 |
 |
Date :
2010-02-17 14:12:03 |
By :
Kwang196 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบใจมากกวาง เเต่เเบบว่า ต้องการเพิ่มข้อมูลลง ใน DataSet ก่อนอะ ทำไงดีง่าาา
|
 |
 |
 |
 |
Date :
2010-02-17 17:47:10 |
By :
artcode |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มนี่หมายถึง insert เสร็จแล้ว query นับจำนวนหรือเปล่าอะ
ป.ล.ขอบใจมาก เมื่อกี้ ที่กวางติด โน้ตช่วยไว้ ผ่านแล้ว แต่..มาใหม่อีกแล้ว ฮ่า ๆ งานเข้า มาเพิ่มเรื่อย ๆ ไม่ขาดสาย
|
 |
 |
 |
 |
Date :
2010-02-17 20:27:36 |
By :
Kwang196 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ก็เรียกข้อมูลมาให้ dataset นะ
Code (VB.NET)
Dim da = New SqlDataAdapter("SELECT EmpCode,EmpRcode,Rcode,DCode FROM Purchase_Order,Receipt,Distribute WHERE EmpCode = '" & tb_ID.Text & "' or EmpRCode = '" & tb_ID.Text & "' or RCode = '" & tb_ID.Text & "' or DCode = '" & tb_ID.Text & "'", SqlConnection1) ' <<< เรียกค่าข้อมูล base เฉพาะที่ต้องการ
da.Fill(ds, "eid")
Dt = ds.Tables("eid")
If ds.Tables("eid").Rows.Count <> 0 Then <<< นับค่า rows ใน datatable ว่าไม่เท่ากับ 0 หรือไม่
temp_mycommand = "Update employee set Status = '0' where EmpID = '" & tb_ID.Text & "'"
Else
temp_mycommand = "Delete from employee where EmpID ='" & tb_ID.Text & "'"
End If
กรณีโน้ต ไม่รู้กวางคิดตรงหรือเปล่า คือ เปลี่ยนเงื่อนไข if ประมาณแบบนี้หรือเปล่า
Code (VB.NET)
If ds.Tables("eid").Rows.Count < DataGridView1.Rows.Count Then ' <<< นับค่า rows ใน datatable เทียบกับข้อมูลที่เลือกไว้ใน DataGridVeiw1
กวางใช้ประมาณนี้ในการเช็คยาด้วย ลองดูนะ
|
 |
 |
 |
 |
Date :
2010-02-18 10:08:00 |
By :
Kwang196 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ใช่ๆ คือถ้าเป็นแบบกวางอะ จะ Query ค่าจาก DB มาไว้ใน Data Set ใช่ป้ะหละ
เเต่ที่โน๊ตต้องการคือ
1. Query ค่าทั้งหมดออกมาจาก DB มาเเสดงไว้ใน DataGridView1 (ทำได้เเละ)
2. เลือกค่าที่เราต้องการได้ทีละหลายๆ Rows เพราะ กำหนด Properties ของDataGridView1 ให้เป็น Multi Selected (ทำได้เเละ)
3. กดปุ่มเพิ่ม ค่าทั้งหมดจะเข้าไปอยู่ในอะไรซักอย่างก่อน(คิดไว้ว่าจะเอา DataSet อะ)เพื่อนับ Rows ว่าเราเลือกไปกี่ Rows(ยังทำไม่ได้)
4. ถ้านับ Rows ในข้อที่ 3 เเล้วผลนับไม่เกินตัวแปรที่เก็บค่าอยู่เเล้วให้เพิ่มข้อมูลที่เลือกลง DataGridView2 ได้อะ
อยากได้ประมาณนี้อะ เเต่ตอนนี้ตัน ทำไม่ได้ เฮ้อออ...
รบกวนพี่ๆ ทุกท่านชี้เเนะทีครับ
|
 |
 |
 |
 |
Date :
2010-02-18 11:34:26 |
By :
artcode |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นก็เหมือนของกวางไง...Grid หลอกง่ะ ใช่ป่ะ ?
|
 |
 |
 |
 |
Date :
2010-02-18 11:47:23 |
By :
Kwang196 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|