question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VB -> C#: Query Expression Syntax not fully implemented

See original GitHub issue

Tried converting the following…

Large code snippet containing various query syntax Imports System.Data Imports System.IO Imports FCA Imports FCA.Data Imports Legacy
Namespace Admin

    Partial Public Class PrintConsignmentAreaRugCards
        Inherits Page

        Dim _currentUser As MpMembershipUser

        Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            _currentUser = Globals.GetCurrentMpUser()
        End Sub

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Trim = String.Empty Then
                MIAIDLabel.Text = "Not found."
                AddLinkButton.Enabled = False
                Exit Sub
            End If

            Using OrderData = New MpOrderDataSet()
                Dim Item =
                        OrderData.GetItemRowByFilter(_currentUser.Location, "reg_num=? AND ptype='29'", TextBox1.Text)
                If Not Item Is Nothing Then
                    MIAIDLabel.Text = Item.mia_id.ToString()
                    AddLinkButton.Enabled = True
                Else
                    MIAIDLabel.Text = "Not found."
                    AddLinkButton.Enabled = False
                End If
            End Using
        End Sub

        Private Sub AddLinkButton_Click(sender As Object, e As EventArgs) Handles AddLinkButton.Click
            If MIAIDLabel.Text.Trim = "" OrElse ListBox1.Items.Cast(Of ListItem).Any(Function(item) item.Value = MIAIDLabel.Text) Then
                Exit Sub
            End If
            ListBox1.Items.Add(New ListItem(TextBox1.Text, MIAIDLabel.Text))
        End Sub

        Private Sub PrintConsignmentAreaRugCards_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
            If ListBox1.Items.Count = 0 Then
                SheetCountLabel.Text = "No sheets needed."
            Else
                If CDec(ListBox1.Items.Count / 4) = CDec(Math.Truncate(ListBox1.Items.Count / 4)) Then
                    SheetCountLabel.Text = CStr(Math.Truncate(ListBox1.Items.Count / 4)) & " sheets needed."
                Else
                    SheetCountLabel.Text = CStr(Math.Truncate(ListBox1.Items.Count / 4) + 1) & " sheets needed."
                End If
            End If
        End Sub

        Private Sub DeleteLinkButton_Click(sender As Object, e As EventArgs) Handles DeleteLinkButton.Click
            If ListBox1.SelectedIndex = -1 Then Exit Sub
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        End Sub

        Private Sub PrintThisLabelButton_Click(sender As Object, e As EventArgs) Handles PrintThisLabelButton.Click
            If ListBox1.Items.Count = 0 Then Exit Sub
            Dim MIAIDList As String = String.Join(",", ListBox1.Items.Cast(Of ListItem).Select(Function(item) item.Value))
            'For Each item As ListItem In ListBox1.Items
            '    MIAIDList &= item.Value & ","
            'Next
            'MIAIDList = MIAIDList.TrimEnd(","c)
            GetPicList()
            Dim Query As String = String.Format("SELECT c.desc AS origin," +
"'0'+RIGHT(RTRIM(p1.sty_link),5) AS rug_id," +
"p2.prv_sku,prv_style AS description,'' AS picture," +
"0 AS our_price,0 AS suggested " +
"FROM `..\{0}\item{0}` i " +
"INNER JOIN `..\..\common\prodcat2` p2 ON p2.prv_sku=i.color " +
"INNER JOIN `..\..\common\prodcat1` p1 ON p1.sty_link=p2.sty_link " +
"LEFT JOIN `..\..\common\codes` c ON c.code=p1.attrib_5 " +
"WHERE p1.prodtype='29' AND c.type='A0529' AND i.mia_id IN ({1})", _currentUser.Location, MIAIDList)
            Using Table As DataTable = Service.GetDataTable(_currentUser.Location, Query)
                If Table IsNot Nothing Then
                    If Table.Rows.Count > 0 Then
                        Dim DV As DataView = Table.DefaultView
                        Dim Drv As DataRowView
                        Dim PrvSKU As String
                        Dim SuggestedPrice As Decimal
                        Dim OurPrice As Decimal
                        For i = 0 To DV.Count - 1
                            Drv = DV.Item(i)
                            PrvSKU = CStr(Drv.Item("prv_sku"))
                            SuggestedPrice = 0
                            OurPrice = 0
                            Globals.GetConsignmentAreaRugRetailPrices(PrvSKU, SuggestedPrice, OurPrice)
                            Drv.Item("our_price") = OurPrice
                            Drv.Item("suggested") = SuggestedPrice
                            Drv.Item("picture") = FindPicFilePath(CStr(Drv.Item("rug_id")))
                        Next
                    End If
                    ConsignmentAreaRugCardCrystalReportSource.ReportDocument.SetDataSource(Table)
                    ConsignmentAreaRugCardCrystalReportSource.DataBind()
                    CrystalReportViewer.Visible = True
                End If
            End Using
        End Sub

        Private Shared Sub GetPicList()
            Dim DirectoryInfo As New DirectoryInfo("\\m-5\rugpics")
            SiteSession.Current.AreaRugPicsFileInfoList = DirectoryInfo.GetFiles("*.jpg")
        End Sub

        Private Shared Function FindPicFilePath(picId As String) As String
            For Each FileInfo As FileInfo In From FileInfo1 In SiteSession.Current.AreaRugPicsFileInfoList Where FileInfo1.Name.Substring(0, 6) = picId
                Return FileInfo.FullName
            Next
            Return String.Empty
        End Function

        Private Sub PrintThemAllButton_Click(sender As Object, e As EventArgs) Handles PrintThemAllButton.Click
            GetPicList()
            Dim Query As String =
                    String.Concat("SELECT c.desc AS origin,",
                                  "'0'+RIGHT(RTRIM(p1.sty_link),5) AS rug_id,p2.prv_sku,prv_style AS description,'' AS picture,",
                                  "0 AS our_price,0 AS suggested ",
                                  "FROM prodcat1 p1 ",
                                  "INNER JOIN prodcat2 p2 ",
                                  "ON p1.sty_link=p2.sty_link ",
                                  "LEFT JOIN codes c ",
                                  "ON c.code=p1.attrib_5 ",
                                  "WHERE p1.prodtype='29' ",
                                  "AND c.type='A0529'")
            Using Table As DataTable = Service.GetDataTable("COMMON", Query)
                If Table IsNot Nothing Then
                    If Table.Rows.Count > 0 Then
                        Dim DV As DataView = Table.DefaultView
                        For i = 0 To DV.Count - 1
                            Dim Drv As DataRowView = DV.Item(i)
                            Dim PrvSKU As String = CStr(Drv.Item("prv_sku"))
                            Dim SuggestedPrice As Decimal = 0
                            Dim OurPrice As Decimal = 0
                            ConsignmentAreaRugLabelLayout.GetRetailPrices(PrvSKU, SuggestedPrice, OurPrice)
                            Drv.Item("our_price") = OurPrice
                            Drv.Item("suggested") = SuggestedPrice
                            Drv.Item("picture") = FindPicFilePath(CStr(Drv.Item("rug_id")))
                        Next
                    End If
                    ConsignmentAreaRugCardCrystalReportSource.ReportDocument.SetDataSource(Table)
                    ConsignmentAreaRugCardCrystalReportSource.DataBind()
                    CrystalReportViewer.Visible = True
                End If
            End Using
        End Sub
    End Class
End Namespace

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
camainccommented, May 2, 2018

I can send you a couple of samples that I manually converted. I’m not very familiar with VB’s syntax either, that’s why I was leaning on you guys 😃

1reaction
GrahamTheCodercommented, May 4, 2018

I’ve been putting it off because I’m not very familiar with vb’s query syntax, so the thing I’m worried about is subtly changing the behavior of the code without realizing. It’s possible some useful information can be gleaned from either the roslyn API or by following a pattern from the compiler itself.

Ideally I’d have some examples of complex queries to test against. If you can provide any examples of queries you’re trying to convert it’d help. I’d also be very happy to accept a pr either just containing just test cases, or with some improved implementation if you want to contribute directly.

Now that someone is actively interested in the result, I will try to make some improvements in the next 2 weeks. Thanks for posting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax error (missing operator) in query expression on vb ...
Here is my problem: Syntax error (missing operator) in query expression 'pinN='. Dim con As New OleDbConnection("PROVIDER = Microsoft.ACE.
Read more >
Standard Query Operators Overview (C#)
The LINQ standard query operators provide query capabilities including filtering, projection, aggregation, and sorting in C#.
Read more >
Query expression syntax: continuations
So, here's a very quick guide. When "into" is used after either a "group x by y" or "select x" clause, it's called...
Read more >
The 10 Most Common Mistakes in C# Programming
Don't fall into one of these C# programming mistakes that even savvy developers can find problematic. Read on to see all 10.
Read more >
C# Query Expression Left Join
All about outer join queries in CRM 2011 and CRM 2013. FullName FROM Leads as lead LEFT OUTER JOIN Tasks as ab ON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found