HOME > .NET Framework > Forum > ดู code ทีค่ะ มัน error อ่ะค่ะ ยังไงก็รบกวนผู้รู้ด้วยนะค่ะ Cannot bind to the property or column 1 in the dataSoruce Parameter name :
ดู code ทีค่ะ มัน error อ่ะค่ะ ยังไงก็รบกวนผู้รู้ด้วยนะค่ะ Cannot bind to the property or column 1 in the dataSoruce Parameter name :
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Windows.Forms
Public Class Dialog1
' Private _dataset As DataSet
' Private _conn As OleDbConnection
' Private _cmd As OleDbCommand
' Private _rowCount As Integer = 0
' Private _Position As Integer = 0
Dim cn As New OleDbConnection(_conStr)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim cmd As New OleDbCommand
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub objCurrencyManager_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCurrencyManager.PositionChanged
End Sub
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSQl As String = "SELECT * FROM Documents"
da.SelectCommand = New OleDbCommand(strSQl, cn)
Try
da.Fill(ds, "Doc")
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
tbid.DataBindings.Add("Text", ds.Tables("Doc"), "1")
tbname.DataBindings.Add("Text", ds.Tables("Doc"), "2")
tbmat.DataBindings.Add("Text", ds.Tables("Doc"), "3")
tbfrom.DataBindings.Add("Text", ds.Tables("Doc"), "4")
tbto.DataBindings.Add("Text", ds.Tables("Doc"), "5")
dtsend.DataBindings.Add("Text", ds.Tables("Doc"), "6")
dtup.DataBindings.Add("Text", ds.Tables("Doc"), "7")
tbid.DataBindings.Add("Text", ds.Tables("Doc"), "8")
tbstore.DataBindings.Add("Text", ds.Tables("Doc"), "9")
cbyear.DataBindings.Add("Text", ds.Tables("Doc"), "10")
TbxFile.DataBindings.Add("Text", ds.Tables("Doc"), "11")
dgvDocuments.DataSource = ds.Tables("Doc")
objCurrencyManager = Me.BindingContext(ds.Tables("Doc"))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfile.Click
With OpenFileDialog1
.Filter = "Portable Document File(*.pdf)|*.pdf|" & _
"doc file(*.doc)|*.doc"
.FileName = ""
If (.ShowDialog() = Windows.Forms.DialogResult.OK) Then
TbxFile.Text = .FileName
End If
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
objCurrencyManager.AddNew()
tbid.Focus()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If MsgBox("คุณแน่ใจหรือว่าต้องการลบข้อมูลนี้", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
objCurrencyManager.RemoveAt(objCurrencyManager.Position)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim cb As New OleDbCommandBuilder(da)
objCurrencyManager.EndCurrentEdit()
Dim iRecordChanged As Integer = da.Update(ds, "Doc")
MsgBox("บันทึกการเปลี่ยนแปลงลงสู่ฐานข้อมูลแล้ว")
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
End Sub
End Class