ปุ๋มอัพเดต อยู่ล่างสุดอะครับ เวลาอัพเดต ข้อมูล มันทับอะครับ คือ เวลาอัพเดต ผมทำการ ค้นหาข้อมูลก่อน และทำการอัพเดตข้อมูลนั้น
สิ่งที่ผิดพลาดคือ ใน access มี id , name , address ,Identification ,type , tel เวลากดปุ่มอัพเดต ข้อมูลของ type มันขึ้น กับ tel ด้วยอะครับ เช่น ผม ใส่ ข้อมูล type เป็น Premiem และ Tel เป็น 0851111111 กดอัพเดต ข้อมูล ของ type คือ Premiem ขึ้นของตาราง Tel ด้วย แบบนี้อะครับ
ID cusname cusAddress cusIdentification type Tel
14 sususu 159/7 1919191919 Premiem Premiem
อันนี้โคด
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Partial Class Product
Inherits System.Web.UI.Page
Dim mycon As OleDbConnection
Dim myAdapter As OleDbDataAdapter
Dim dataset As New DataSet
Dim mycmd As OleDbCommand
Dim intId As Integer
Dim myreader As OleDbDataReader
Dim myupdate As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mycon = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=d:\inventory.mdb")
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
mycmd = New OleDbCommand("Insert INTO customer(ID,cusname,cusAddress,cusIdentification,type,Tel) values (txtId.text,txtName.text,txtAdd.text,txtIden.text," & type.SelectedValue & ",txtTelephone.text)", mycon)
mycmd.Parameters.AddWithValue("@ID", txtId.Text)
mycmd.Parameters.AddWithValue("@cusname", txtName.Text)
mycmd.Parameters.AddWithValue("@cusAddress", txtAdd.Text)
mycmd.Parameters.AddWithValue("@cusIdentification", txtIden.Text)
If Type.SelectedValue = "Premiem" Then
mycmd.Parameters.AddWithValue("@type", Type.SelectedValue)
ElseIf Type.SelectedValue = "Silver" Then
mycmd.Parameters.AddWithValue("@type", Type.SelectedValue)
Else
mycmd.Parameters.AddWithValue("@type", Type.SelectedValue)
End If
mycmd.Parameters.AddWithValue("@Tel", txtTelephone.Text)
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
txtkey.Text = ""
txtId.Text = ""
txtName.Text = ""
txtAdd.Text = ""
txtIden.Text = ""
txtTelephone.Text = ""
End Sub
Protected Sub Button8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadd.Click
mycon.Open()
mycmd = New OleDbCommand("select* from Customer", mycon)
Dim dataRead As OleDbDataReader = mycmd.ExecuteReader
While dataRead.Read()
intId = (dataRead("ID"))
End While
mycon.Close()
txtId.Text = intId + 1
txtName.Focus()
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndel.Click
mycmd = New OleDbCommand("DELETE FROM Customer WHERE ID = " & txtId.Text, mycon)
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
txtId.Text = ""
txtName.Text = ""
txtAdd.Text = ""
txtIden.Text = ""
type.Text = ""
txtTelephone.Text = ""
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearch.Click
mycon.Open()
If rbid.Checked Then
mycmd = New OleDbCommand("SELECT * FROM Customer WHERE ID = @ID", mycon)
mycmd.Parameters.AddWithValue("@ID", txtkey.Text)
myreader = mycmd.ExecuteReader()
While myreader.Read()
txtId.Text = CStr(myreader.Item("id"))
txtName.Text = CStr(myreader.Item("cusname"))
txtAdd.Text = CStr(myreader.Item("cusaddress"))
txtIden.Text = CStr(myreader.Item("cusidentification"))
type.Text = CStr(myreader.Item("type"))
txtTelephone.Text = CStr(myreader.Item("Tel"))
End While
End If
If rbname.Checked Then
mycmd = New OleDbCommand("SELECT * FROM Customer WHERE cusname = @cusname", mycon)
mycmd.Parameters.AddWithValue("@cusname", txtkey.Text)
myreader = mycmd.ExecuteReader()
While myreader.Read()
txtId.Text = CStr(myreader.Item("id"))
txtName.Text = CStr(myreader.Item("cusname"))
txtAdd.Text = CStr(myreader.Item("cusaddress"))
txtIden.Text = CStr(myreader.Item("cusidentification"))
type.Text = CStr(myreader.Item("type"))
txtTelephone.Text = CStr(myreader.Item("Tel"))
End While
End If
If rbiden.Checked Then
mycmd = New OleDbCommand("SELECT * FROM Customer WHERE cusIdentification = @cusIdentification", mycon)
mycmd.Parameters.AddWithValue("@ID", txtkey.Text)
myreader = mycmd.ExecuteReader()
While myreader.Read()
txtId.Text = CStr(myreader.Item("id"))
txtName.Text = CStr(myreader.Item("cusname"))
txtAdd.Text = CStr(myreader.Item("cusaddress"))
txtIden.Text = CStr(myreader.Item("cusidentification"))
type.Text = CStr(myreader.Item("type"))
txtTelephone.Text = CStr(myreader.Item("Tel"))
End While
End If
myreader.Close()
mycon.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnclear.Click
txtkey.Text = ""
txtId.Text = ""
txtName.Text = ""
txtAdd.Text = ""
txtIden.Text = ""
txtTelephone.Text = ""
rbid.Checked = False
rbname.Checked = False
rbiden.Checked = False
type.Visible = True
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupdate.Click
myupdate = "update customer set cusname = @cusname,cusAddress = @cusAddress,cusidentification = @cusidentification,type = @type,Tel = @Tel where ID=" & txtId.Text & " "
mycmd = New OleDbCommand(myupdate, mycon)
mycmd.Parameters.AddWithValue("@cusname", txtName.Text)
mycmd.Parameters.AddWithValue("@Address", txtAdd.Text)
mycmd.Parameters.AddWithValue("@cusIdentification", txtIden.Text)
mycmd.Parameters.AddWithValue("@type", type.Text)
If type.SelectedValue = "Premiem" Then
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
ElseIf type.SelectedValue = "Silver" Then
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
Else
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
End If
mycmd.Parameters.AddWithValue("@Tel", txtTelephone.Text)
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
txtkey.Text = ""
txtId.Text = ""
txtName.Text = ""
txtAdd.Text = ""
txtIden.Text = ""
txtTelephone.Text = ""
End Sub
End Class
mycmd.Parameters.AddWithValue("@type", type.Text)
If type.SelectedValue = "Premiem" Then
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
ElseIf type.SelectedValue = "Silver" Then
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
Else
mycmd.Parameters.AddWithValue("@type", type.SelectedValue)
End If
mycmd.Parameters.AddWithValue("@Tel", txtTelephone.Text)