p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning VB.NET Databases (http://p2p.wrox.com/book-beginning-vb-net-databases-147/)
-   -   Beginning Visual Basic .NETDatabase Programming (http://p2p.wrox.com/book-beginning-vb-net-databases/83343-beginning-visual-basic-netdatabase-programming.html)

Kieuvietphuong April 19th, 2011 04:35 AM

Beginning Visual Basic .NETDatabase Programming
Dear sir
I started learning programming practice database in the book Beginning Visual Basic. NET Database Programming 2001 but I encountered some errors while trying to add records to the DataTable, and data binding between the text book into DataTable
I used Funtions

Public Function TaoTableDataset(ByRef strConnection As String, ByVal strTablename As String, ByVal _
                  strSQlorStoredProc As String, ByVal Bln As Boolean, ByRef dsDataset As  _
                  DataSet) As DataSet   
        Dim sqlConn As New SqlClient.SqlConnection(StrConn)
            Dim da As New SqlClient.SqlDataAdapter()
            Dim dttb As DataTable = New DataTable(strTablename)
            da.TableMappings.Add("Table", strTablename)
            Dim cmdTable As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQlorStoredProc, sqlConn)
          If Bln Then
            cmdTable.CommandType = CommandType.StoredProcedure
            cmdTable.CommandType = CommandType.Text
        End If
          da.SelectCommand = cmdTable
        Return dsDataset
    End Function

to created, fill dataset and shows up datagirdviews

      Protected MyBindingManagerBase As BindingManagerBase
      Protected dsData As DataSet
      Private Sub FrmDNCapThe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim T_SQL As String = "Select * from [DLTHE]"
            Dim bln As Boolean = False
            Dim dsData As New DataSet
            Dim dttb As DataTable = New DataTable("DLTHE")
            dsData = TaoTableDataset(StrConn, "DLTHE", T_SQL, bln, dsData)
            dtgDuLieuThe.DataSource = dsData
            dtgDuLieuThe.DataMember = "DLTHE"
            MyBindingManagerBase = BindingContext(dsData, "DLTHE")
            dtgDuLieuThe.DataSource = dsData.Tables("DLTHE").DefaultView   
      End Sub

but the error occurred in: Binding_Control_Field_datatable()

Sub Binding_Control_Field_datatable()
        Dim dsData As New DataSet     
            Me.txtSoDN.DataBindings.Add(New Binding("Text", dsData, "DLTHE.SODN"))
        txtMaDVi.DataBindings.Add(New Binding("Text", dsData, "DLTHE.Madvi"))
        txtTenDVi.DataBindings.Add(New Binding("Text", dsData, "DLTHE.TENDVI"))
        cboLoaiDT.DataBindings.Add(New Binding("Text", dsData, "DLTHE.LOAIDT"))
        TxtSoLD.DataBindings.Add(New Binding("Text", dsData, "DLTHE.SOLD"))
        cboLoai_DK.DataBindings.Add(New Binding("Text", dsData, "DLTHE.LOAI_DK"))
        txtTuNgay.DataBindings.Add(New Binding("Text", dsData, "DLTHE.TUNGAY"))
        txtDenNgay.DataBindings.Add(New Binding("Text", dsData, "DLTHE.DENNGAY"))
        txtSoTien.DataBindings.Add(New Binding("Text", dsData, "DLTHE.SOTIEN"))
        txtVanBan.DataBindings.Add(New Binding("Text", dsData, "DLTHE.VANBAN"))
        txtSotien_Dong.DataBindings.Add(New Binding("Text", dsData, "DLTHE.SOTIEN_DONG"))
        txtSoDN.DataBindings.Add(New Binding("Text", dsdata, "DLTHE.STT"))
        txtNgayLapPhieu.DataBindings.Add(New Binding("Text", dsdata, "DLTHE.NGAYLAPHIEU"))
        TxtGhiChu.DataBindings.Add(New Binding("Text", dsData, "DLTHE.GHICHU"))
        txtNgay.DataBindings.Add(New Binding("Text", dsData, "DLTHE.NGAY"))
    End Sub

"Child list for field DLTHE cannot be created."

Pleased shows me mistake

All times are GMT -4. The time now is 10:22 AM.

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.