Home > Software design >  Visual Basic removes underscore from my aspx.vb code
Visual Basic removes underscore from my aspx.vb code

Time:10-31

enter image description hereWe have a asp.net project that needs adjusting. I have opened the project as a website in VB.

Very annoying is that VB removes the underscore from the &vbCrLf & _ resulting in errors when running in the browser.

Is this an option I can switch off ? original code:

   txtProdOrder.Text = oSqlDb.GetFieldValue("select ph.ProdHeaderOrdNr from T_PartDispatch PD " & vbCrLf & _
                         "Inner Join dbo.T_ProductionHeader As ph    On PH.ProdHeaderDossierCode = PD.ProdHeaderDossierCode " & vbCrLf & _
                         "Where PD.PicklistNr = N' & Replace(TXTPICKLISTNR.Text, %, ) & '")
                MsgBox(wat)

wat vb does:

"select ph.ProdHeaderOrdNr from T_PartDispatch PD " & vbCrLf &
                         "Inner Join dbo.T_ProductionHeader As ph    On PH.ProdHeaderDossierCode = PD.ProdHeaderDossierCode " & vbCrLf &
                         "Where PD.PicklistNr = N' & Replace(TXTPICKLISTNR.Text, %, ) & '"

enter code here

CodePudding user response:

I see ZERO but beyond ZERO reason to include a vbcrlf in what amounts to raw SQL.

If this was text for a text box, then fine.

So, this code:

    txtprodOrder.Text =
        oSqlDb.GetFieldValue("select ph.ProdHeaderOrdNr from T_PartDispatch PD " &
                  "Inner Join dbo.T_ProductionHeader As ph On PH.ProdHeaderDossierCode = PD.ProdHeaderDossierCode " &
                  "Where PD.PicklistNr = N' & Replace(TXTPICKLISTNR.Text, %, ) & '")

So, you really don't need the vbcrlf at all.

You just creating some SQL and that is a string of sql text.

Keep in mind, that you might want to use the "newer" Rosilyn compiler features.

That mean you can do this:

    txtprodOrder.Text =
        oSqlDb.GetFieldValue(
           "select ph.ProdHeaderOrdNr from T_PartDispatch PD
           Inner Join dbo.T_ProductionHeader As ph 
               On PH.ProdHeaderDossierCode = PD.ProdHeaderDossierCode
           Where PD.PicklistNr = N'" & Replace(TXTPICKLISTNR.Text, "%", ""))

However, the above last example will ONLY work if you using a asp.net "application". If you are opening (and deploying) as a web site (but not a asp.net web site application), then of course IIS (the web server) will be doing your compile for you, and you have to go back to using the "&" sign.

but, either way, you do NOT need the vbcrlf in that sql. as noted, if this was some text you are shoving into a text box, then sure/fine/good, you need the vbcrlf.

Also, looking at that code, I don't think it would compile correctly anyway.

(it is wrong as posted)

Say this would/should be ok:

    txtprodOrder.Text = oSqlDb.GetFieldValue("select ph.ProdHeaderOrdNr from T_PartDispatch PD " &
                    "Inner Join dbo.T_ProductionHeader As ph  On PH.ProdHeaderDossierCode = PD.ProdHeaderDossierCode " &
                    "Where PD.PicklistNr = N'" & Replace(TXTPICKLISTNR.Text, "%", "xxxxx") & "'")

Now, I added "xxxx", since your posted code is missing the replace value.

But, what you have/had looks incorrect anyway,

So, with Rosylin, you can type in free form sql, don't even need the "&" between each line.

but, this does in general means you have to move (or re-name) app_code.

but, this assumes you have a "asp.net web site application".

If you have a "asp.net web site"?

Then IIS is doing the compile, and not visual studio.

As noted, you can (and should) drop the vbcrlf from the sql, but you need the last syntax. And your replace command looks beyond messed up.

Replace the "xxxx" with what your replace is supposed to change the "%" to.

And goodness forbids, pass a sql command object to that routine, so at least you can use parameters here - as your sending raw user input from a text box - and that is VERY but VERY bad idea.

  • Related