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 03: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
Code:

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)
        sqlConn.Open()
            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
        Else
            cmdTable.CommandType = CommandType.Text
        End If
          da.SelectCommand = cmdTable
          da.Fill(dsDataset)     
        Return dsDataset
    End Function

to created, fill dataset and shows up datagirdviews
Code:

      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")
           
            Binding_Control_Field_datatable()         
            dtgDuLieuThe.DataSource = dsData.Tables("DLTHE").DefaultView   
         
      End Sub

but the error occurred in: Binding_Control_Field_datatable()
Code:

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 08:01 PM.

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