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 > VB2010&Access คือผมมีปัญหาเกี่ยวกับปุ่มเพิ่ม แก้ไขข้อมูลในตารางครับ แนะนำทีนะครับ



 

VB2010&Access คือผมมีปัญหาเกี่ยวกับปุ่มเพิ่ม แก้ไขข้อมูลในตารางครับ แนะนำทีนะครับ

 



Topic : 103777



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



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




คือผมสามารถเพิ่มข้อมูลลงไปในตารางได้ตามปกตินะครับแต่ผมไม่สามารถที่จะแก้ไขข้อมูลได้ แล้วโปรแกรมก็ไม่ฟ้องว่า error จุดไหนแต่ไม่สามารถคลิกในตารางเพื่อแก้ไขข้อมูลได้ครับ

SS

Code (VB.NET)
Public Class vehicle
    Dim x As Integer
    Dim strCheck As String 'ตัวแปลเก็บข้อมูลคำสั่ง sql เอาไว้เช็คข้อผิดพลาด
    Dim strSQL As String 'ตัวแปลเก็บข้อมูลคำสั่ง sql สำหรับ เพิ่มข้อมูล
    Dim ID As String 'DPass ใช้เก็บรหัสข้อมูลหรัสหน่วยงานจากที่ผู้ใช้งานเลือก


    Private Sub vehicle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized

        cb_search.SelectedIndex = 0
        ComboBox1.SelectedIndex = 0
        ComboBox2.SelectedIndex = 0
        ComboBox3.SelectedIndex = 0

        'เชื่อมต่อฐานข้อมูล.............................................................................
        Try 'คำสั่งดัก error สั่งให้ทำ
            With CnMysql
                If .State = ConnectionState.Open Then .Close() 'ตรวจสอบสถานะว่าตัวคอนเน็คฐานข้อมูลเปิดอยู่หรือเปล่า
                .ConnectionString = strcon 'กำหนดว่าฐานข้อมูลอยู่ที่ใหนในเครื่อง เชื่อมต่อฐานข้อมูลอะไร
                .Open() 'เปิดการใช้งานฐานข้อมูล
            End With

        Catch 'ถ้า error จะมาทำงานที่ Catch อัตโนมัติ
            MessageBox.Show("ติดต่อฐานข้อมูลไม่ได้") 'แสดงข้อความสาเหตุของการ error
        End Try 'สิ้นสุดคำสั่ง try catch
        'สิ้นสุด Code เชื่อมต่อฐานข้อมูล...............................................................
        Dim sqlDePart As String = "SELECT * FROM vehiclekind ORDER BY Vehicle_ID"
        Dim dsPart As New DataSet()
        da = New OleDb.OleDbDataAdapter(sqlDePart, CnMysql)
        da.Fill(dsPart, "DePart")
        If dsPart.Tables("DePart").Rows.Count <> 0 Then
            cmbkind.DataSource = dsPart.Tables("DePart")
            cmbkind.DisplayMember = dsPart.Tables("DePart").Columns("Vehicle_ID").ToString()
            cmbkind.ValueMember = dsPart.Tables("DePart").Columns("Vehicle_kind").ToString()
        End If

        ShowGrid() 'ดึงข้อมูลมาโชว์ในกริด
    End Sub

    Private Sub bt_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_add.Click
        'ตรวจสอบการกรอกข้อมูลของผู้ใช้งาน............................................................
        If txt_no.Text = "" Then
            MessageBox.Show("กรุณากรอกข้อมูลรหัส")
            Exit Sub
            txt_no.Focus()
        ElseIf txt_name.Text = "" Then
            MessageBox.Show("กรุณากรอกข้อมูลชื่อ")
            txt_name.Focus()
        End If
        'สิ้นสุดการตรวจสอบการกรอกข้อมูลของผู้ใช้งาน.......................................................

        'ตรวจสอบว่า หรัสหน่วยงานที่กรอกมานั้นมีอยู่แล้วในฐานข้อมูลหรือไม่........................
        strCheck = "SELECT * FROM tblvehicle WHERE Vehicle_StudentNo = '" & txt_no.Text & "'"
        da = New OleDb.OleDbDataAdapter() 'รีเฟรช da
        ds = New DataSet() 'รีเฟรช ds

        da = New OleDb.OleDbDataAdapter(strCheck, CnMysql)
        da.Fill(ds, "Chk_Emp")
        If ds.Tables("Chk_Emp").Rows.Count <> 0 Then
            MessageBox.Show("รหัสนี้มีอยู่แล้วในฐานข้อมูล", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub 'สั่งให้มันหยุดการทำงาน
        End If
        'สิ้นสุดตรวจสอบว่า หรัสหน่วยงานที่กรอกมานั้นมีอยู่แล้วในฐานข้อมูลหรือไม่........................


        'บันทึกข้อมูลลงใน Employee .........................................................
        'คำสั่ง sql สำหรับบันทึกข้อมูล INSERT INTO ชื่อตาราง (ชื่อฟิวล์1,ชื่อฟิวล์2,...,ชื่อฟิวล์ N) VALUES('ค่าของฟิว 1',ค่าฟิว 2,...,'ค่าฟิว N')
        strSQL = "Insert into tblvehicle(Vehicle_StudentNo,Vehicle_StudentName , Vehicle_StudenLastName, Vehicle_StudentBranch, Vehicle_StudentDegree, Vehicle_StudentYear, Vehicle_StudentPhone, Vehicle_StudentEmail, Vehicle_MemberNo, Vehicle_MemberName, Vehicle_MemberLastName, Vehicle_Memberoccupation, Vehicle_MemberPhone, Vehicle_MemberEmail, Vehicle_kind, Vehicle_registration, Vehicle_trademark, Vehicle_Color, Vehicle_jv, Vehicle_in) values('" & txt_no.Text & "','" & txt_name.Text & "','" & txt_lastname.Text & "','" & ComboBox1.Text & "','" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & txt_phone.Text & "','" & txt_email.Text & "','" & txt_no2.Text & "','" & txt_name2.Text & "','" & txt_lastname2.Text & "','" & txt_occ.Text & "','" & txt_phone2.Text & "','" & txt_email2.Text & "','" & cmbkind.SelectedValue.ToString() & "','" & txt_red.Text & "','" & txt_td.Text & "','" & txt_color.Text & "','" & txt_jv.Text & "','" & txt_in.Text & "')"

        Try
            With cm
                .CommandType = CommandType.Text 'กำหนดประเภทคำสั่ง
                .CommandText = strSQL ' ส่งค่าคำสั่ง sql ให้ object
                .Connection = CnMysql ' บอกเส้นทางเชื่อมต่อ
                .ExecuteNonQuery() ' สั่งให้ทำงาน

                MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว")
                ShowGrid() 'แสดงข้อมูลในกริด
                ClearText() 'ล้างข้อมูลใน text
            End With
        Catch
            MessageBox.Show("การเพิ่มข้อมูลผิดพลาด")
            Exit Sub
        End Try 'สิ้นสุดบันทึกข้อมูลลงใน Employee .........................................................
    End Sub

    '.... Sub ฟังชั่นของการโชว์ข้อมูลใน datagridview 
    Sub ShowGrid()
        Dim strShow As String
        strShow = "SELECT * FROM tblvehicleQuery ORDER BY Vehicle_StudentNo"
        ds = New DataSet()
        da = New OleDb.OleDbDataAdapter(strShow, CnMysql)
        da.Fill(ds, "Show")
        If ds.Tables("Show").Rows.Count <> 0 Then
            DataGridView1.DataSource = ds.Tables("Show")

        End If

    End Sub '.... สิ้นสุด Sub ฟังชั่นของการโชว์ข้อมูลใน datagridview ... สิ้นสุด Sub ฟังชั่นของการโชว์ข้อมูลใน datagridview


    '.... Sub ฟังชั่นของการเคลียร์ข้อมูลใน textbox
    Sub ClearText()
        txt_no.Text = ""
        txt_name.Text = ""
        txt_lastname.Text = ""
        ComboBox1.SelectedValue = 0
        ComboBox2.SelectedValue = 0
        ComboBox3.SelectedValue = 0
        txt_phone.Text = ""
        txt_email.Text = ""
        txt_no2.Text = ""
        txt_name2.Text = ""
        txt_lastname2.Text = ""
        txt_occ.Text = ""
        txt_phone2.Text = ""
        txt_email2.Text = ""
        cmbkind.SelectedValue = 0
        txt_red.Text = ""
        txt_td.Text = ""
        txt_color.Text = ""
        txt_jv.Text = ""
        txt_in.Text = ""
    End Sub '.... สิ้นสุด Sub ฟังชั่นของการเคลียร์ข้อมูลใน textbox

    Private Sub bt_Canceled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Canceled.Click
        ClearText()
    End Sub

    Private Sub bt_cor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_cor.Click
        'แก้ไขข้อมูล......................................................................
        'ตรวจสอบการเลือกข้อมูลเพื่อจะแก้ไข ว่าผู้ใช้งานเลือกหรือยัง
        If txt_no.Text = "" Then
            MessageBox.Show("กรุณาเลือกข้อมูลที่ต้องการแก้ไข")
            Exit Sub 'คำสั่งออกจากการทำงาน
        End If
        'เริ่มต้นการแก้ไข...................................
        'Update ชื่อตาราง set ชื่อฟิว = ค่าที่แก้ไข Where เงื่อนไข
        strSQL = "Update tblvehicle set Vehicle_StudentName ='" & txt_name.Text & "',Vehicle_StudenLastName = '" & txt_lastname.Text & "',Vehicle_StudentBranch = '" & ComboBox1.Text & "',Vehicle_StudentDegree='" & ComboBox2.Text & "',Vehicle_StudentYear='" & ComboBox3.Text & "',Vehicle_StudentPhone='" & txt_phone.Text & "',Vehicle_StudentEmail='" & txt_email.Text & "',Vehicle_MemberNo='" & txt_no2.Text & "',Vehicle_MemberName='" & txt_name2.Text & "',Vehicle_MemberLastName='" & txt_lastname2.Text & "',Vehicle_Memberoccupation='" & txt_occ.Text & "',Vehicle_MemberPhone='" & txt_phone2.Text & "',Vehicle_MemberEmail='" & txt_email2.Text & "',Vehicle_kind=" & cmbkind.SelectedValue.ToString() & ",Vehicle_registration='" & txt_red.Text & "',Vehicle_trademark='" & txt_td.Text & "',Vehicle_Color='" & txt_color.Text & "' ,Vehicle_jv='" & txt_jv.Text & "',Vehicle_in='" & txt_in.Text & "' where Vehicle_StudentNo='" & ID & "'"
        Try
            With cm
                .CommandType = CommandType.Text 'กำหนดประเภทคำสั่ง
                .CommandText = strSQL ' ส่งค่าคำสั่ง sql ให้ object
                .Connection = CnMysql ' บอกเส้นทางเชื่อมต่อ
                .ExecuteNonQuery() ' สั่งให้ทำงาน

                MessageBox.Show("การแก้ไขเรียบร้อยแล้ว")
                ShowGrid() 'แสดงข้อมูลในกริด
                ClearText() 'ล้างข้อมูลใน text
            End With
        Catch
            MessageBox.Show("การแก้ไขข้อมูลผิดพลาด")
            Exit Sub
        End Try
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
        If e.RowIndex < 0 Then 'ป้องกันการคลิกเลือกที่หัวคอลัม ถ้าเลือกหัวจะไม่ให้ทำงาน
            Exit Sub
        End If

        'โชว์ข้อมูลจากการเลือกข้อมูลในกิดวิว

        Dim sqlSelect As String 'เป็นตัวแปลเก็บข้อมูลที่ดึงจากฐานข้อมูลตามที่ผู้ใช้งานเลือก
        ID = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() 'เลือกข้อมูลจาก Cellsที่0 = เลขที่อัตรานั่นเอง^^
        sqlSelect = "Select * from tblvehicle Where Vehicle_StudentNo ='" & ID & "'" 'ดึงข้อมูลที่มีเลขที่ตัราตรงกับ DPass ที่เลือก
        da = New OleDb.OleDbDataAdapter(sqlSelect, CnMysql) 'สั่งให้ DataAdapter ทำงานตามคำสั่ง sqlSelect
        ds = New DataSet() 'รีเฟทดาต้าเซ็ต
        da.Fill(ds, "Emp_Show") 'เอาข้อมมูลที่ da ดึงมาได้ใส่ไว้ใน ds

        If ds.Tables("Emp_Show").Rows.Count <> 0 Then
            txt_no.Text = ID
            txt_name.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentName").ToString()
            txt_lastname.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudenLastName").ToString()
            ComboBox1.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentBranch").ToString()
            ComboBox2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentDegree").ToString()
            ComboBox3.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentYear").ToString()
            txt_phone.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentPhone").ToString()
            txt_email.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_StudentEmail").ToString()
            txt_no2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_MemberNo").ToString()
            txt_name2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_MemberName").ToString()
            txt_lastname2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_MemberLastName").ToString()
            txt_occ.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_Memberoccupation").ToString()
            txt_phone2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_MemberPhone").ToString()
            txt_email2.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_MemberEmail").ToString()
            cmbkind.SelectedValue = ds.Tables("Emp_Show").Rows(0)("Vehicle_kind").ToString()
            txt_red.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_registration").ToString()
            txt_td.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_trademark").ToString()
            txt_color.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_Color").ToString()
            txt_jv.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_jv").ToString()
            txt_in.Text = ds.Tables("Emp_Show").Rows(0)("Vehicle_in").ToString()
        End If
    End Sub

    Private Sub txt_search_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_search.TextChanged
        Dim strwhere As String
        Dim strShow As String
        Select Case cb_search.Text
            Case "รหัสนักศึกษา"
                strwhere = " where Vehicle_StudentNo like '%" & txt_search.Text & "%'"
            Case "ชื่อ"
                strwhere = " where Vehicle_StudentName like '%" & txt_search.Text & "%'"
        End Select

        strShow = "SELECT * FROM tblvehicleQuery " & strwhere & " ORDER BY Vehicle_StudentNo"
        ds = New DataSet()
        da = New OleDb.OleDbDataAdapter(strShow, CnMysql)
        da.Fill(ds, "Show")
        DataGridView1.DataSource = ds.Tables("Show")
        If ds.Tables("Show").Rows.Count = 0 Then
            MessageBox.Show("ไม่มีข้อมูลตามเงื่อนไขที่กำหนด")
        End If
    End Sub

    Private Sub bt_del_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class




Tag : .NET, Ms Access, VB.NET, VS 2010 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-12-19 07:35:57 By : parawichai View : 1007 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

มี Tools สุดยอดอย่าง Visual Studio แล้วทำไมไม่ Debug ดูล่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-12-19 08:54:25 By : mr.win
 


 

No. 2



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



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


Debug Error อยู่ไหน อ้าวมาให้ดูหน่อย งี้ตอบไม่ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-12-19 09:09:52 By : angelrings0
 

 

No. 3



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



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


คือมันไม่เตือนError อะไรสักอย่างเลยอะครับ โค้ดดึงข้อมูลเอามาไว้ในTextเพื่อแก้ไข หรือโค้ดปุ่มแก้ไขก็ใส่หมดแล้วอะครับ แต่พอเวลาคลิกไปที่ตารางข้อมูลมันไม่โชว์ในTextอะครับมันเลยแก้ไขไม่ได้

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-12-19 09:58:54 By : parawichai
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : VB2010&Access คือผมมีปัญหาเกี่ยวกับปุ่มเพิ่ม แก้ไขข้อมูลในตารางครับ แนะนำทีนะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่