1.11M Members

trying to dispay data through datagrid view

 
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

 
0
 

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

 
0
 

Thank you avd

Question Answered as of 10 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