1,105,226 Community Members

trying to dispay data through datagrid view

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

When to trying to display data to datagrid view using query i got an error
"a column named date already belongs to this datatable in net 2008"

  Dim dt As New DataTable
        Try

            myConnection = New SqlConnection(connectionstring)
            myConnection.Open()


            Dim cmd As New SqlClient.SqlCommand
            With cmd
                .CommandText = "SELECT [Date],[Totalamount] FROM [Mobilization] where [Contract_Name]='" & ComboBox1.Text & "' AND [Client_Name]='" & ComboBox2.Text & "'"
                .CommandType = CommandType.Text

                .Connection = myConnection
            End With

            dt.Load(cmd.ExecuteReader)
            dt.Columns.Add(New DataColumn("Date", System.Type.GetType("System.String")))
            dt.Columns.Add(New DataColumn("Total Amount", System.Type.GetType("System.Double")))

            DataGridView1.DataSource = dt

            myConnection.Close()


        Catch err As Exception
            MsgBox(err.Message, MsgBoxStyle.Exclamation)
        End Try

I couldn't find what is the error

Member Avatar
__avd
Posting Genius (adatapost)
6,703 posts since Oct 2008
Reputation Points: 1,811 [?]
Q&As Helped to Solve: 1,272 [?]
Skill Endorsements: 61 [?]
Moderator
 
0
 

Don't add columns that are already been added by Load method. Remove line #17 to 19.

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

Thank you avd

Question Answered as of 7 Months Ago by __avd
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article