?
Solved

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

Posted on 2006-10-25
2
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
gangwisch earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

762 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