Solved

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

Posted on 2006-10-25
2
251 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

22 Experts available now in Live!

Get 1:1 Help Now