Translate from C# to VB .NET

Add-in Express™ Support Service
That's what is more important than anything else

Translate from C# to VB .NET
 
Subscribe
Leon Lai Kan




Posts: 87
Joined: 2018-12-20
Hi,

I am studying this blog.

Importing data from SQL databases and other sources to Microsoft Excel
https://www.add-in-express.com/creating-addins-blog/2013/10/30/excel-importing-data-sql-databases/


I am using various code converters to translate the FIRST code snippet to VB .NET, and they give me different translations.


So, how do you translate this:

OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder()
{ ConnectionString = connectionDialog.ConnectionString };



One converter translates it as follows:

Dim builder As OleDbConnectionStringBuilder = New OleDbConnectionStringBuilder() With {
.ConnectionString = connectionDialog.ConnectionString }


Another converter completely deleted the line between { } .


Can anyone give me the correct translation?


Thanks
Leon
Posted 08 Jan, 2019 07:06:32 Top
Andrei Smolin


Add-in Express team


Posts: 15595
Joined: 2006-05-11
Hello Leon,

Dim builder As OleDbConnectionStringBuilder = New OleDbConnectionStringBuilder()
builder.ConnectionString = connectionDialog.ConnectionString

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Jan, 2019 07:12:51 Top
Leon Lai Kan




Posts: 87
Joined: 2018-12-20
Hi, Andrei

Is your answer (VB) in 2 separate lines?

It seems to me that the original C# code is a single line:
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder()
{ ConnectionString = connectionDialog.ConnectionString };


as there is no semicolon at the end of the first line. (Sorry, I don't know much about C#)

Thanks
Leon
Posted 08 Jan, 2019 07:28:54 Top
Andrei Smolin


Add-in Express team


Posts: 15595
Joined: 2006-05-11
Hello Leon,

In C#, you see a shortcut way to create an OleDbConnectionStringBuilder object and set its ConnectionString property. Yes, this can be done using two lines in VB.NET.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Jan, 2019 07:50:53 Top
Leon Lai Kan




Posts: 87
Joined: 2018-12-20
Thanks Andrei

I have a few other problems with converters. I hope you won't mind helping me with the conversions.

I really need to be able to connect with SQL server (where my stored procedures and SAP Tables reside) in order to develop my first Excel add-in. And this is the most difficult step!

Best Regards,
Leon
Posted 08 Jan, 2019 07:57:12 Top
Andrei Smolin


Add-in Express team


Posts: 15595
Joined: 2006-05-11
Hello Leon,

No problem. I may be unable to answer some questions, though. I would recommend that you find a VB.NET tutorial (example) explaining these things.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Jan, 2019 02:20:27 Top