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 > ผมมีปัญหาเกี่ยวกับ Update กับ Delete ครับ รบกวนท่านผู้รู้ทีนะครับ



 

ผมมีปัญหาเกี่ยวกับ Update กับ Delete ครับ รบกวนท่านผู้รู้ทีนะครับ

 



Topic : 036247



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



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




Code (VB.NET)
Public Class AddChemForm

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.Close()
    End Sub

    Private Sub AddChemForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call GetData()
    End Sub
    Sub GetData()
        strSql = "Select Chemical.ChemId AS รหัสสารเคมี, Chemical.ChemName AS ชื่อสารเคมี, " & _
                 "Chemical.ChemUnit AS หน่วยนับ, Chemical.Chemtotal AS จำนวนคงคลัง From Chemical"

        DA.SelectCommand.CommandText = strSql
        DA.Fill(DS, "Getchem")
        DS.Tables("Getchem").Clear()
        DA.Fill(DS, "Getchem")

        DataGridView1.DataSource = DS.Tables("Getchem")
        DataGridView1.ReadOnly = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        strSql = "Insert Into Chemical (ChemId, ChemName, ChemUnit, Chemtotal) Values ('" & _
                TextBox1.Text & "','" & TextBox2.Text & "','" & _
                TextBox3.Text & "','" & NumericUpDown1.Text & "')"
        Try
            With Comm
                .CommandText = strSql
                .CommandType = CommandType.Text
                .Connection = Conn
                .ExecuteNonQuery()
            End With

            Call GetData()
            MessageBox.Show("เพิ่มข้อมูลสำเร็จ", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show("มีสารเคมีชนิดนี้อยู่แล้วในฐานข้อมูล", "พบข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        strSql = "Update Chemical set ChemId = '" & TextBox1.Text & "', ChemName = '" & _
              TextBox2.Text & "', ChemUnit = '" & TextBox3.Text & ", Chemtotal = '" & _
              NumericUpDown1.Text & "'"

        Try
            With Comm
                .CommandText = strSql
                .CommandType = CommandType.Text
                .Connection = Conn
                .ExecuteNonQuery()
            End With


            MessageBox.Show("แก้ไขข้อมูลเสร็จสิ้น", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show("การแก้ไขข้อมูลผิดพลาด", "", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
        End Try
        Call GetData()
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        NumericUpDown1.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
        Button1.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        strSql = "Delete * From Chemical where ChemId = '" & TextBox1.Text & "'"

        Try
            With Comm
                .CommandText = strSql
                .CommandType = CommandType.Text
                .Connection = Conn
                .ExecuteNonQuery()
            End With


            MessageBox.Show("ลบข้อมูลเสร็จสิ้น", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show("การลบข้อมูลผิดพลาด", "", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
        End Try
        Call GetData()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        NumericUpDown1.Text = ""
        Button1.Enabled = True
    End Sub

End Class




Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-12-26 14:23:10 By : nuinyzaa View : 1159 Reply : 3
 

 

No. 1



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



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


มัน Error ตรงไหนอะครับ แล้ว Error ว่ายังไงอะครับ






Date : 2009-12-26 16:03:58 By : Nameless
 


 

No. 2



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



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


ตรง Delete * from ....

ใช้เป็น delete from
Date : 2009-12-26 16:40:02 By : otomokung
 

 

No. 3



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



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


ขอบคุณครับ
Date : 2009-12-29 20:13:34 By : nuinyzaa
 

   

ค้นหาข้อมูล


   
 

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