hello.
just i need the conversion of this code written in vb.net:

Dim SQL =
      <SQL>
          sql statement
      </SQL>

thank you.

Dani AI

Generated

The snippet posted by uses VB.NET XML-literal syntax, which is a VB-only convenience. C# has no direct XML-literal equivalent, so many automatic converters (such as the ones mentioned by ) will fail on this construct. Also, as observed, the inner text in the sample is a placeholder; the real text and whether the literal contains embedded VB expressions or attributes affect the correct translation.

A straightforward C# approach is to build the same XML with System.Xml.Linq (XElement/XDocument). Example patterns:

using System.Xml.Linq;

var SQL = new XElement("SQL", "your SQL text here");

// If the SQL contains characters that must not be escaped, wrap it in CDATA:
var SQLWithCData = new XElement("SQL",
    new XCData("SELECT * FROM MyTable WHERE Name = 'O''Reilly'"));

// Retrieve results:
string xml = SQL.ToString();   // includes tags
string inner = SQL.Value;      // inner text only

Notes and cautions: if the original VB literal embedded expressions or attributes, construct the element using variables and new XAttribute(...) or concatenate/inject values when creating child content. If the XML is only used to carry a query string (no XML manipulation needed), keeping a plain string may be simpler. Never build SQL by concatenating user data inside XML — prefer parameterized queries to avoid SQL injection.

Because VB XML literals can include whitespace nodes and expression interpolation, converting more complex literals requires manual reconstruction of the XElement tree in C#, not just a text substitution.

Recommended Answers

All 6 Replies

Here you have online converter.

commented: Hey! Great tip! +14

thank you,but it didn't work with this code.

Line 3 : sql statement is no code in whatever computer language, so it is very hard to translate.. You could just as well try to translate a poem to C#, it will not work.

Line 3 : sql statement is no code in whatever computer language, so it is very hard to translate.. You could just as well try to translate a poem to C#, it will not work.

For loop Haiku:

For(int i = 0;
i < theString.Length;
i = i + 1)
commented: Great! +14

: You made my day!:D
Just have difficulty counting the syllabes 5-7-5 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.