Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > .NET Framework > Forum > การส่งค่าจาก DataGridView ครับ ข้อมูลไม่ต่อจากค่าเดิมที่มีอยู่ครับ



 

การส่งค่าจาก DataGridView ครับ ข้อมูลไม่ต่อจากค่าเดิมที่มีอยู่ครับ

 



Topic : 038105



โพสกระทู้ ( 121 )
บทความ ( 0 )



สถานะออฟไลน์




การทำงานดูตามรูปเลยนะครับ
s1

code เมื่อปุ่มเพิ่มรายการอัตโนมัติ
Code (VB.NET)
 Dim d_adap As SqlDataAdapter
        Dim d_set As DataSet
        d_set = New DataSet
        Dim temp_sql As String

        temp_sql = "select Dog_no,Dog_name,Dog_sex,Dog_color,Vacci_no,Vac_no,Vac_ID,Vac_Name " & _
        "from Vaccination, Vaccination_detail, kennel_dog,Vaccine_Type " & _
        "where Dog_no = Dog_Id and Vacci_ID = Vacci_No and Vac_no = Vac_ID " & _
        "and next_date = '" & DateTime.Now.Year.ToString() & "/" & DateTime.Now.Month.ToString() & "/" & DateTime.Now.Day.ToString() & "'"

        d_adap = New SqlDataAdapter(temp_sql, sqlConnection)
        d_adap.Fill(d_set, "Vaccination_List")

        DataGridView2.Columns(0).DataPropertyName = "Dog_no"
        DataGridView2.Columns(1).DataPropertyName = "Dog_Name"
        DataGridView2.Columns(2).DataPropertyName = "Dog_Sex"
        DataGridView2.Columns(3).DataPropertyName = "Dog_Color"
        DataGridView2.Columns(4).DataPropertyName = "Vacci_no"

        DataGridView2.DataSource = d_set.Tables("Vaccination_List")

        DataGridView2.Columns(4).Visible = False

        lb_qtyDog.Text = DataGridView2.RowCount

---------------------------------------------------------------------------------------------------------------------------------------------------
s2
Code โหลดข้อมูลสุนัขขึ้นมาเเดสงครับ
Code (VB.NET)
        Dim d_adap As SqlDataAdapter
        Dim d_set As DataSet
        d_set = New DataSet

        d_adap = New SqlDataAdapter("Select Dog_ID,Dog_Name,Dog_Sex,Dog_Color,Dog_Status " & _
                                    "from Kennel_Dog Where Dog_Status <> 'DE' and Dog_Status <> 'SO'", sqlConnection)

        d_adap.Fill(d_set, "Kennel_Dog")
        DataGridView1.DataSource = d_set.Tables("Kennel_Dog")

        DataGridView1.Columns("Dog_ID").DisplayIndex = 0
        DataGridView1.Columns("Dog_Name").DisplayIndex = 1
        DataGridView1.Columns("Dog_Sex").DisplayIndex = 2
        DataGridView1.Columns("Dog_Color").DisplayIndex = 3
        DataGridView1.Columns("Dog_Status").DisplayIndex = 4

        DataGridView1.Columns(0).HeaderText = "รหัสสุนัข"
        DataGridView1.Columns(1).HeaderText = "ชื่อสุนัข"
        DataGridView1.Columns(2).HeaderText = "เพศสุนัข"
        DataGridView1.Columns(3).HeaderText = "สีสุนัข"
        DataGridView1.Columns(4).HeaderText = "สถานะสุนัข"

        DataGridView1.Columns(0).Width = 120
        DataGridView1.Columns(1).Width = 220
        DataGridView1.Columns(2).Width = 60
        DataGridView1.Columns(3).Width = 120
        DataGridView1.Columns(4).Width = 120


Code เมื่อกดปุ่มเพิ่มรายการครับ
Code (VB.NET)
    Private Sub bt_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Add.Click
        Dim i As Integer = 0

        For i = 0 To DataGridView1.Rows.Count - 1
            If DataGridView1.Rows(i).Selected Then
                Dim j As Integer = Sale.DataGridView2.Rows.Add
                Vaccination.DataGridView2.Rows(j).Cells(0).Value = DataGridView1.Rows(i).Cells(0).Value
                Vaccination.DataGridView2.Rows(j).Cells(1).Value = DataGridView1.Rows(i).Cells(1).Value
                Vaccination.DataGridView2.Rows(j).Cells(2).Value = DataGridView1.Rows(i).Cells(2).Value
                Vaccination.DataGridView2.Rows(j).Cells(3).Value = DataGridView1.Rows(i).Cells(3).Value
                'Vaccination.DataGridView2.Rows(j).Cells(4).Value = DataGridView1.Rows(i).Cells(4).Value
            End If
        Next
        Me.Close()
    End Sub


ผลลัพธ์การทำงานมันได้ตามรูปนี้ครับ
s3



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-02-01 15:39:56 By : artcode View : 3445 Reply : 11
 

 

No. 1



โพสกระทู้ ( 373 )
บทความ ( 0 )



สถานะออฟไลน์


datagrid view คุณ sort column "รหัสสุนัข" ไว้หรือเปล่า






Date : 2010-02-01 16:10:10 By : numenoy
 


 

No. 2



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มันไปทับ row เดิมเนอะ ต้องให้มัน add new row ดิ

ถ้าใช้ datatable ผมจะใช้

Code (VB.NET)
Dim Dt As DataTable = New DataTable()
Dim Dr As DataRow = Dt.NewRow()
...
...
...
Dt.Rows.Add(Dr)


แต่ถ้าเป็น datagridview ต้องกลับไปลองที่บ้านเพราะที่ทำงานไม่ได้ลง vs ไว้
Date : 2010-02-01 16:19:15 By : tungman
 

 

No. 3



โพสกระทู้ ( 121 )
บทความ ( 0 )



สถานะออฟไลน์


เเล้วให้มัน add new row ยังไงหละครับพี่ tungman ผมทำไม่ได้อะครับ

เครียด ๆๆๆ
Date : 2010-02-01 17:18:26 By : artcode
 


 

No. 4



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


คราวหน้าให้ทำงานที่ datatable ให้เสร็จก่อนนะ ใช้ datagridview สำหรับแสดงผลอย่างเดียวพอ

ทำใน datagridview มันก็ทำได้แหละ แต่ทำใน datatable สะดวกกว่า ส่งค่าไป method อื่นก็ง่าย

ผมทำแบบ oop ไม่เคยใช้ datagridview ทำงานเลย ใช้แสดงผลอย่างเดียว

Code (VB.NET)
Dim NewRow As DataGridViewRow = New DataGridViewRow()
Dim Cell1 As DataGridViewCell = New DataGridViewTextBoxCell()
Dim Cell2 As DataGridViewCell = New DataGridViewTextBoxCell()
Dim Cell3 As DataGridViewCell = New DataGridViewTextBoxCell()

Cell1.Value = "Cell1"
Cell2.Value = "Cell2"
Cell3.Value = "Cell3"

NewRow.Cells.Add(Cell1)
NewRow.Cells.Add(Cell2)
NewRow.Cells.Add(Cell3)

DataGridView1.Rows.Add(NewRow)

Date : 2010-02-01 19:19:20 By : tungman
 


 

No. 5



โพสกระทู้ ( 121 )
บทความ ( 0 )



สถานะออฟไลน์


ลองทำเเล้ว ยังไม่ได้ครับพี่ tungman หรือเพราะผมไม่เคยใช้รูปแบบนี้เลยยังไม่เข้าใจครับ
ตอนนี้ผมเอา code ส่วนนี้ไว้ในปุ่ม เพิ่มรายการครับ
Code (VB.NET)
 Private Sub bt_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Add.Click

 Dim NewRow As DataGridViewRow = New DataGridViewRow()

        Dim Cell1 As DataGridViewCell = New DataGridViewTextBoxCell()
        Dim Cell2 As DataGridViewCell = New DataGridViewTextBoxCell()
        Dim Cell3 As DataGridViewCell = New DataGridViewTextBoxCell()
        Dim Cell4 As DataGridViewCell = New DataGridViewTextBoxCell()
        Dim Cell5 As DataGridViewCell = New DataGridViewTextBoxCell()

        Cell1.Value = "Dog_ID"
        Cell2.Value = "Dog_Name"
        Cell3.Value = "Dog_Sex"
        Cell4.Value = "Dog_Color"
        Cell5.Value = "Dog_Status"

        NewRow.Cells.Add(Cell1)
        NewRow.Cells.Add(Cell2)
        NewRow.Cells.Add(Cell3)
        NewRow.Cells.Add(Cell4)
        NewRow.Cells.Add(Cell5)

        Vaccination.DataGridView2.Rows.Add(NewRow)


เวลากดเพิ่มรายการถ้า DataGridView2 หน้า Vaccination ไม่มีข้อมูลครับ เเล้วมันจะเเสดงแบบนี้ครับ
รูปครับ
errror1


-------------------------------------------------------------------------------------------------------------------------------------------
อันนี้ Error ครับ เป็นเมื่อตอนที่ DataGridView2 หน้า Vaccination มีข้อมูลอยู่เเล้ว เเล้วเราไปกดเพิ่มครับ
errror2
Date : 2010-02-01 21:10:50 By : artcode
 


 

No. 6



โพสกระทู้ ( 121 )
บทความ ( 0 )



สถานะออฟไลน์


ยังทำไม่ได้ เลยครับ
พี่ๆช่วยผมทีครับ

เครียดมากๆ พยามทำมาตลอดเลยครับ ทั้งหาเพิ่มเติม ทั้งลองผิดลองถูก เเต่ไม่ได้เลยครับ
Date : 2010-02-09 22:30:25 By : artcode
 


 

No. 7



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ผมลองทำโปรเจ็คง่ายๆ ดู

มี controls 2 ตัว คือ

1. DataGridView1
2. AddButton

1

Code (VB.NET)
Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Column1 As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn()
        Column1.Name = "Column1"
        Column1.HeaderText = "Column1"

        Dim Column2 As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn()
        Column2.Name = "Column2"
        Column2.HeaderText = "Column2"

        DataGridView1.Columns.Add(Column1)
        DataGridView1.Columns.Add(Column2)
    End Sub

    Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
        Dim NewRow As DataGridViewRow = New DataGridViewRow()
        Dim Cell1 As DataGridViewCell = New DataGridViewTextBoxCell()
        Dim Cell2 As DataGridViewCell = New DataGridViewTextBoxCell()

        Cell1.Value = "Cell1"
        Cell2.Value = "Cell2"

        NewRow.Cells.Add(Cell1)
        NewRow.Cells.Add(Cell2)

        DataGridView1.Rows.Add(NewRow)
    End Sub

End Class

Date : 2010-02-09 23:13:50 By : tungman
 


 

No. 8



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


หรืออีกทางเลือก ที่ผมแนะนำไว้ตั้งแต่แรก คือให้ทำงานใน DataTable แล้วใช้ DataGridView แค่แสดงผลเท่านั้น (ไม่แนะนำให้เพิ่ม/ลดข้อมูลที่ DataGridView โดยตรง)

ก็ตามนี้ https://www.thaicreate.com/dotnet/forum/037562.html
Date : 2010-02-09 23:19:15 By : tungman
 


 

No. 9



โพสกระทู้ ( 373 )
บทความ ( 0 )



สถานะออฟไลน์


มาโผล่กระทู้นี้อีกแล้ว พี่ก็ว่าน้องต้องเจอปัญหานี้จริงๆ ก็อย่างที่คิดจริงๆ ด้วย
เอาใจช่วยจริงๆ โปรเจ็คน้องเนี้ย 555+

Code (VB.NET)
For Each dgvr As System.Windows.Forms.DataGridViewRow In Me.DataGridView2.SelectedRows 'บอกว่า loop ทุกๆ ค่า rows ที่เลือกไว้
Dim dgr As System.Windows.Forms.DataGridViewRow = dgvr.Clone() 'ให้ทำการ clone structure ของ row นี้ไว้ นั่นคือ ได้ columes ของ datagridview นี้ไว้ แต่ไม่ได้ values นะ
            For i As Integer = 0 To dgvr.Cells.Count - 1
                dgr.Cells(i).Value = dgvr.Cells(i).Value
            Next 'loop นี้บอกว่า ให้ copy ค่าของทุกๆ cells ใน dgvr เข้าทุกๆ cells ของ dgr
            DataGridView1.Rows.Add(dgr)' เพิ่ม rows ใหม่ใน datagridview1 นั่นก็คือ grid ของน้องที่อยากให้เอาค่าไปลงแหล่ะครับ เจ้า "รายการสุนัขที่ต้องฉีด"
            Me.DataGridView2.Rows.Remove(dgvr)'ลบ rows เก่าที่น้อง double click แหล่ะครับ "เจ้ารายชื่อสุนัขที่ต้องฉีด"
Next


พอติดตามโปรเจ็คน้องมาได้สักพัก จึงรู้ว่า น้องใช้ listview control จะดีกว่านะ แต่คงไม่ทันแล้ว...ก็ด้น code กันต่อไป สู้ๆ
Date : 2010-02-10 08:29:50 By : numenoy
 


 

No. 10

Guest


ดึงข้อมูลปกติ ออกมาแล้วเอาค่า add กลับเข้าไปก็น่าจะได้ หรือ นับจำนวน row แล้ว +1 แล้วเอาค่าไปใส่ก็ได้ครับ ลองดูครับ
Date : 2010-02-27 11:23:00 By : บอย
 


 

No. 11



โพสกระทู้ ( 1,603 )
บทความ ( 1 )



สถานะออฟไลน์


ค่ะ เห็นด้วยกะการมองว่า GRIDVIEW ใช้เป็นเพียงตัว USER INTERFACE
ไปทำ DATABASE จะดีกว่าเพราะค่าอื่นๆที่เกี่ยวข้องจะถูก update ตามไปด้วย
อีกอย่าง ส่วนตัวจะแนะนำเพื่อนๆที่มาถามเสมอว่าไม่ควรใช้ edit template ของ Grid
เขียนแยกต่างหากจะสะดวกมากกว่าค่ะ ตัว Grid เองก้อซับซ้อนมากพออยู่แล้ว

update ที่ database แล้วกลับไป refresh ให้ grid แสดงผลก็พอค่ะ
Date : 2010-02-27 14:14:08 By : blurEye
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การส่งค่าจาก DataGridView ครับ ข้อมูลไม่ต่อจากค่าเดิมที่มีอยู่ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่