[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-10-25
2
Medium Priority
?
258 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 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