CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008

    Question Shape command for MSHFlexGrid


    I am using MSHFlexGrid and following is the code:

    Dim strCn As String

    strCn = "connection string"

    Dim strSh As String

    strSh = "SHAPE {SELECT * FROM `Customer`} AS Customers APPEND ({SELECT * FROM `Order`} AS Orders RELATE Cust_ID TO Cust_ID) AS Orders"

    With Adodc1
    .ConnectionString = strCn
    .RecordSource = strSh
    End With

    Set MSHFlexGrid1.DataSource = Adodc1

    But when I run code it gives me following error:

    Invalid SQL Statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'.

    What can be done????



  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008

    Re: Shape command for MSHFlexGrid

    "connection string" is not a valid connection string
    I do not use the data control nor do I use shape so I am not real sure about your select.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Shape command for MSHFlexGrid

    Here's a sample that uses OLE (which is old)

    Private Sub Command1_Click()
        Dim cnLvConnection As ADODB.Connection
        Set cnLvConnection = New ADODB.Connection
        Dim rsLvRecordset As ADODB.Recordset
        Set rsLvRecordset = New ADODB.Recordset
        With cnLvConnection
            .Provider = "MSDataShape.1"
            .ConnectionString = "Data Source=" & App.Path & "\db1.mdb;" _
                              & "Data Provider=Microsoft.Jet.OLEDB.4.0;"
            With rsLvRecordset
                .CursorLocation = adUseClient
                .CursorType = adOpenStatic
                .LockType = adLockReadOnly
            End With
            Set rsLvRecordset = .Execute("SHAPE {SELECT c.CustomerName As Customer, c.CustomerID FROM Customers c ORDER BY c.CustomerName} As Customers" _
                                       & " APPEND ((SHAPE {SELECT oh.OrderNumber As [Order No], oh.CustomerID, oh.OrderHeaderID FROM OrderHeaders oh ORDER BY oh.OrderNumber} As OrderHeaders" _
                                       & "          APPEND ({SELECT od.OrderLine As [Line], od.OrderLineDescription As [Description], od.OrderLineQuantity As Quantity, od.OrderHeaderID FROM OrderDetails od ORDER BY od.OrderLine} As OrderDetails" _
                                       & "          RELATE OrderHeaderID TO OrderHeaderID))" _
                                       & " RELATE CustomerID TO CustomerID)")
        End With
        '   Setup Grid
        Set Me.MSHFlexGrid1.Recordset = rsLvRecordset
        Me.MSHFlexGrid1.ColWidth(1, 0) = 0 ' c.CustomerID
        Me.MSHFlexGrid1.ColWidth(1, 1) = 0 ' oh.CustomerID
        Me.MSHFlexGrid1.ColWidth(2, 1) = 0 ' oh.OrderHeaderID
        Me.MSHFlexGrid1.ColWidth(3, 2) = 0 ' od.OrderHeaderID
        '   Tidy up
        If Not rsLvRecordset Is Nothing Then
            If rsLvRecordset.State <> adStateClosed Then
            End If
            Set rsLvRecordset = Nothing
        End If
        If Not cnLvConnection Is Nothing Then
            If cnLvConnection.State <> adStateClosed Then
            End If
            Set cnLvConnection = Nothing
        End If
    End Sub
    Private Sub Form_Load()
        Me.MSHFlexGrid1.FixedCols = 0
    End Sub
    '  Edit the cell, without the update
    Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
       If KeyAscii = vbKeyReturn Then   'enter key
        'move to next cell.
            With MSHFlexGrid1
                If .Col + 1 <= .Cols - 1 Then
                    .Col = .Col + 1
                    If .Row + 1 <= .Rows - 1 Then
                        .Row = .Row + 1
                        .Col = 0
                        .Row = 1
                        .Col = 0
                    End If
                End If
            End With
        ElseIf KeyAscii = vbKeyBack Then   'back space key
            With MSHFlexGrid1
                'back space out the entered characters
                If Len(.Text) Then
                    .Text = Left(.Text, Len(.Text) - 1)
                End If
            End With
            With MSHFlexGrid1
                .Text = .Text & Chr(KeyAscii)
            End With
        End If
    End Sub

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2008

    Thumbs up Re: Shape command for MSHFlexGrid

    Thank you so much! it worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)