Solved

How to populate axspreadsheet from SQL Server db

Posted on 2011-02-23
4
653 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:alsam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:suvmitra
ID: 34970725
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"
0
 
LVL 1

Author Comment

by:alsam
ID: 34973510
It is specified in My.Settings.ControllingConnectionString
Its not a problem....
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 35021637
0
 
LVL 1

Author Closing Comment

by:alsam
ID: 35021730
Right
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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