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,027

HOME > .NET Framework > Forum > บันทึกข้อมูลที่โชว์จาก Datagridview โดยดึงข้อมูลมาจาก Access 2003 ไม่ขึ้นคะ



 

บันทึกข้อมูลที่โชว์จาก Datagridview โดยดึงข้อมูลมาจาก Access 2003 ไม่ขึ้นคะ

 



Topic : 056426



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



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




สร้างข้อมูลจาก Access 2003 แล้วให้ Datagridview โชว์ข้อมูลขึ้นมาคะ พอเรากดที่ข้อมูลใน DataGridview ข้อมูลก็จะแสดงในแต่ละ Textbox ที่ได้กำหนดไว้

สิ่งที่ต้องการจะทำคือ ต้องการแก้ไขใน Textbox หรือ เมื่อข้อมูลโชว์ใน Textbox พอกดบันทึกข้อมูล ต้องการให้ข้อมูลเพิ่มเข้าไปใน Access คะ

แต่ลองทำแล้วไม่ขึ้น + Error อยู่หลายครั้ง ต้องทำการส้ราง Code ยังไงคะ

Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Public Class frmOrderProducts
    Dim cn As New OleDbConnection
    Dim cm As New OleDbCommand
    Dim da As New OleDbDataAdapter
    Dim ds As New DataSet

    Dim cal As Integer
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim conn As String = "Provider = Microsoft.jet.oledb.4.0; Data Source = C:\infoproductsDB.mdb"
        cn.ConnectionString = conn
        cm.Connection = cn
    End Sub
    Private Sub DataGridView_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView.CellMouseUp
        With DataGridView
            Try
                txtIDType.Text = .Rows.Item(e.RowIndex).Cells("IDType").Value
                txtID.Text = .Rows.Item(e.RowIndex).Cells("ID").Value
                txtNameType.Text = .Rows.Item(e.RowIndex).Cells("NameType").Value
                txtName.Text = .Rows.Item(e.RowIndex).Cells("Name").Value
                txtPriceUnit.Text = .Rows.Item(e.RowIndex).Cells("PriceUnit").Value
            Catch ex As Exception
            End Try
        End With
    End Sub
    Public Sub SelectProductType()
        DataGridView.Columns.Item(0).HeaderText() = "รหัสสินค้า"
        DataGridView.Columns.Item(1).HeaderText() = "รหัสประเภทสินค้า"
        DataGridView.Columns.Item(2).HeaderText() = "ชื่อประเภทสินค้า"
        DataGridView.Columns.Item(3).HeaderText() = "ชื่อสินค้า"
        DataGridView.Columns.Item(4).HeaderText() = "ราคาต่อหน่วย"
    End Sub
    Private Sub btNovel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNovel.Click
        cm.CommandText = "SELECT * FROM ProductsNovel"
        da.SelectCommand = cm
        da.Fill(ds, "ProductsNovel")
        DataGridView.DataSource = ds.Tables("ProductsNovel")
        SelectProductType()
    End Sub
    Private Sub btSStory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSStory.Click
        cm.CommandText = "SELECT * FROM ProductsShortStory"
        da.SelectCommand = cm
        da.Fill(ds, "ProductsShortStory")
        DataGridView.DataSource = ds.Tables("ProductsShortStory")
        SelectProductType()
    End Sub
    Private Sub btCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCom.Click
        cm.CommandText = "SELECT * FROM ProductsCom"
        da.SelectCommand = cm
        da.Fill(ds, "ProductsCom")
        DataGridView.DataSource = ds.Tables("ProductsCom")
        SelectProductType()
    End Sub
    Private Sub btCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCal.Click
        cal = txtPriceUnit.Text * txtAmount.Text
        txtCost.Text = cal
    End Sub
    Private Sub btClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClear.Click
        ds.Clear()
    End Sub
    Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
        cm.CommandText = "INSERT INTO OrderProducts (IDOrder,CusID,Amount,CostTotal) values (" & txtSlip.Text & "," & txtCusID.Text & "," & txtAmount.Text & "," & txtCost.Text & ")"
        cn.Open()
        cm.ExecuteReader()
        cn.Close()
        MessageBox.Show("การบันทึกเสร็จเรียบร้อย", "ยืนยัน")
    End Sub

End Class


ผลลัพธ์แบบฟอร์มที่ทำไว้คะ


รบกวนด้วยคะ ต้องแก้ Code ยังไงบ้างคะ



Tag : .NET, Ms Access, Win (Windows App), LINQ, VB.NET, VS 2008 (.NET 3.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-02-23 07:45:39 By : ppc493 View : 3083 Reply : 8
 

 

No. 1



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



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


บรรทัดที่ 65
เปลี่ยน ExecuteReader
เป็น ExecuteNonQuery
ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 08:50:17 By : kaimuk
 


 

No. 2



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



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


ลองแล้วคะ ไม่ได้ ขึ้น Error (ตามรูปเลยคะ)

Error2
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 11:27:46 By : ppc493
 

 

No. 3



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



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


ดูเหมือน cm.CommandText จะเปลี่ยนนิครับ แต่ผมเห็นไม่หมด ลบกวนลง Code บรรทัดนี้ทั้งหมด ได้ไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 13:09:59 By : kaimuk
 


 

No. 4



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



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


Code (VB.NET)
Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
        Try
            cm.CommandText = "INSERT INTO OrderProducts (IDOrder,CusID,IDType,NameType,ID,Name,PriceUnit,Amount,CostTotal) values (" & txtSlip.Text & "," & txtCusID.Text & "," & txtIDType.Text & "," & txtNameType.Text & "," & txtID.Text & "," & txtName.Text & "," & txtPriceUnit.Text & "," & txtAmount.Text & "," & txtCost.Text & ")"
            cn.Open()
            cm.ExecuteReader()
            cn.Close()
            MessageBox.Show("การบันทึกเสร็จเรียบร้อย", "ยืนยัน")
        Catch ex As Exception
            MessageBox.Show("คุณกรอกข้อมูลไม่ครบถ้วน กรุณากรอกใหม่อีกครั้ง", "คำเตือน")
        End Try
    End Sub


จากที่สังเกตอ่าคะ ที่มัน Error ก็เพราะ NameType กับ Name ที่รับค่าเป็น Text แต่ถ้าเป็นตัวเลขมันจะไม่ Error รับค่าได้ปกติคะ
แต่ต้องการจะให้แก้ไขข้อมูลที่เป็น Text หรือ ภาษาไทยได้อ่าคะ ต้องแก้ไขยังไงดีคะ รบกวนด้วยคะะ ขอบคุณมากๆค่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 14:42:07 By : ppc493
 


 

No. 5



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



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


ต้องใส่ ตัวนี้ด้วยครับกรณีเป็นตัวอักษร ตัวนี้อ่ะครับ '
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 15:29:56 By : kaimuk
 


 

No. 6



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



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


ประมาณนี้ครับ
Code (VB.NET)
 Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
  
        Dim _String As New System.Text.StringBuilder
        Try
            _String.Append("INSERT INTO OrderProducts ")
            _String.Append("(IDOrder,CusID,IDType,NameType,ID,Name,PriceUnit,Amount,CostTotal) ")
            _String.Append("values ('")
            _String.Append(txtSlip.Text & "','")
            _String.Append(txtCusID.Text & "','")
            _String.Append(txtIDType.Text & "','")
            _String.Append(txtNameType.Text & "','")
            _String.Append(txtID.Text & "','")
            _String.Append(txtName.Text & "',")
            _String.Append(txtPriceUnit.Textt & ",")
            _String.Append(txtAmount.Text & ",")
            _String.Append(txtCost.Text & ")")

            cm.CommandText = _String.ToString
            cN.Open()
            cm.ExecuteReader()
            cN.Close()
            MessageBox.Show("การบันทึกเสร็จเรียบร้อย", "ยืนยัน")
        Catch ex As Exception
            MessageBox.Show("คุณกรอกข้อมูลไม่ครบถ้วน กรุณากรอกใหม่อีกครั้ง", "คำเตือน")
        End Try
    End Sub


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 15:45:15 By : kaimuk
 


 

No. 7



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



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


ขอบคุณมากๆๆเลยคะ ได้แล้ว ^^"
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-23 21:35:39 By : ppc493
 


 

No. 8

Guest


แก้ยังไงคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-23 03:58:47 By : lusifer
 

   

ค้นหาข้อมูล


   
 

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