Solved

Problem adding a column to a DataTable on second occurence of New DataTable()

Posted on 2006-10-25
2
252 Views
Last Modified: 2010-04-23
Hello,

Here's my sequence

Public Class frmMain
    Inherits System.Windows.Forms.Form

    Private dsADP As New DataSet
    Private tblTA_ADP_Hrs As DataTable

.....

    Private Sub BindData()

'fill table with sql statement

   daADP.SelectCommand = New Odbc.OdbcCommand(sSQLTA_ADPHrs, dcADP)
            daADP.Fill(dsADP, "tblTA_ADP_Hrs")

......

'Add column to table

Dim dcHours As New DataColumn
                dcHours.DataType = System.Type.GetType("System.Double")
                dcHours.AllowDBNull = True
                dcHours.ColumnName = "Regular_Hours"
                dsADP.Tables("tblTA_ADP_Hrs").Columns.Add(dcHours)             (this is the line it dies on second time through)


This column adds fine, but if I run my program a second time (fill a datagrid and create csv file) and then attempt to BindData() again it fails when trying to add this column.  I have a Try - Catch loop that dumps out to my error string.

At the end of my create file routine, I'm trying to "refresh" all tables, relations, and columns but still get error.  I have a feeling it thinks the column is already there??

dsADP.Tables("tblTA_ADP_Hrs").Rows.Clear()
        dsADP.Tables("tblTA_ADP_Hrs").Dispose()
        dsADP.Relations.Clear()
        dgJBTimeAttendance.Refresh()


Any thoughts would be greatly appreciated.

Thanks,
JMO9966

0
Comment
Question by:JMO9966
2 Comments
 
LVL 10

Accepted Solution

by:
gangwisch earned 250 total points
ID: 17807015
it's because you can not have two of the same columns named the same thing. this is the line that is killing you
dcHours.ColumnName = "Regular_Hours"
maybe you can try doing a  dsADP.Tables("tblTA_ADP_Hrs").Columns.remove("Regular_Hours") before adding
0
 

Author Comment

by:JMO9966
ID: 17807107
Thanks Gangwisch!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now