Link to home
Start Free TrialLog in
Avatar of alsam
alsam

asked on

How to populate axspreadsheet from SQL Server db

Hi, can enyone provide me with the code how can I populate my axspreadsheet with data from SQL Server database...
I tried with the code below but it does not work
"Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'msdatasrc.DataSource'."

Please help...
I would apprecate a lot...
Private Sub GetData(ByVal selectCommand As String)

        Try
            
            Dim connectionString As String = My.Settings.ControllingConnectionString

            Me.dataAdapter = New SqlDataAdapter(selectCommand, connectionString)

            Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)

            table.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.dataAdapter.Fill(table)
            Me.AxSpreadsheet1.DataSource = table


        Catch ex As SqlException
            MessageBox.Show("NOK")
        End Try

    End Sub

Open in new window

Avatar of suvmitra
suvmitra
Flag of India image

you must specify a connection in your code ..which is missing.

            Dim connectionString As String = "Data Source=localhost;Initial Catalog=DatabaseName;User Id=sa;Password=pass"
Avatar of alsam
alsam

ASKER

It is specified in My.Settings.ControllingConnectionString
Its not a problem....
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alsam

ASKER

Right