VB.net Namespace ......

Hi

In the following code I am not quite sure what "Namespace JLSQLBrowser.Controls" is.
I got the code by converting the C# code below. Is this just a C# thing or does it do something in VB.net


Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel

Namespace JLSQLBrowser.Controls
      Public Partial Class TpSqlEdit
            Inherits UserControl
            Public Sub New()
                  InitializeComponent()
            End Sub

            Private Sub buttonGetData_Click(sender As Object, e As EventArgs)
                  PopulateFromSql()
            End Sub
            Private Sub PopulateFromSql()
                  Try
                        ' DataTable Construction with Adapter and Connection
                        Dim conn = New SqlConnection(textBoxCS.Text)
                        Dim strSql = richTextBoxSQLEdit.Text
                        conn.Open()
                        Dim da = New SqlDataAdapter(strSql, conn)
                        Dim dt = New System.Data.DataTable()
                        da.Fill(dt)

                        ' Define the active Worksheet
                        Dim sht = TryCast(Globals.ThisAddIn.Application.ActiveSheet, Worksheet)

                        Dim rowCount = 0
                        progressBarGetData.Minimum = 1
                        progressBarGetData.Maximum = dt.Rows.Count

                        ' Loop thrue the Datatable and add it to Excel
                        For Each dr As DataRow In dt.Rows
                              rowCount += 1
                              For i As var = 1 To dt.Columns.Count
                                    ' Add the header the first time through
                                    If rowCount = 2 Then
                                          ' Add the Columns using the foreach i++ to get the cell references
                                          If sht IsNot Nothing Then
                                                sht.Cells(1, i) = dt.Columns(i - 1).ColumnName
                                          End If
                                    End If
                                    ' Increment value in the Progress Bar
                                    progressBarGetData.Value = rowCount
                                    ' Add the Columns using the foreach i++ to get the cell references
                                    If sht IsNot Nothing Then
                                          sht.Cells(rowCount, i) = dr(i - 1).ToString()
                                    End If
                                    ' Refresh the Progress Bar
                                    progressBarGetData.Refresh()
                              Next
                        Next
                  Catch ex As Exception
                        Throw New Exception(ex.ToString())
                  End Try

            End Sub
      End Class
End Namespace

'###########################################################
'###########################################################

using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace JLSQLBrowser.Controls
{
    public partial class TpSqlEdit : UserControl
    {
        public TpSqlEdit()
        {
            InitializeComponent();
        }

        private void buttonGetData_Click(object sender, EventArgs e)
        {
            PopulateFromSql();
        }
        private void PopulateFromSql()
        {
            try
            {
                // DataTable Construction with Adapter and Connection
                var conn = new SqlConnection(textBoxCS.Text);
                var strSql = richTextBoxSQLEdit.Text;
                conn.Open();
                var da = new SqlDataAdapter(strSql, conn);
                var dt = new System.Data.DataTable();
                da.Fill(dt);

                // Define the active Worksheet
                var sht = Globals.ThisAddIn.Application.ActiveSheet as Worksheet;

                var rowCount = 0;
                progressBarGetData.Minimum = 1;
                progressBarGetData.Maximum = dt.Rows.Count;

                // Loop thrue the Datatable and add it to Excel
                foreach (DataRow dr in dt.Rows)
                {
                    rowCount += 1;
                    for (var i = 1; i < dt.Columns.Count + 1; i++)
                    {
                        // Add the header the first time through
                        if (rowCount == 2)
                        {
                            // Add the Columns using the foreach i++ to get the cell references
                            if (sht != null) sht.Cells[1, i] = dt.Columns[i - 1].ColumnName;
                        }
                        // Increment value in the Progress Bar
                        progressBarGetData.Value = rowCount;
                        // Add the Columns using the foreach i++ to get the cell references
                        if (sht != null) sht.Cells[rowCount, i] = dr[i - 1].ToString();
                        // Refresh the Progress Bar
                        progressBarGetData.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
             
        }
    }
}
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CrashmanCommented:
The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types.
http://msdn.microsoft.com/en-us/library/z2kcy19k%28v=vs.80%29.aspx
0
BuggyCoderCommented:
its nothing more than a way of organizing your code. However at runtime and for MSIL your type name will be name of your namespace + "." + typename, like in your case it will be:-

JLSQLBrowser.Controls.TpSqlEdit.

Namespaces are only known to vb/c#, IL is unaware of them....
so you need not to worry, just mention the namespace in imports wherever you intend to use TpSqlEdit type in your code, everything works fine...
0
anarki_jimbelSenior DeveloperCommented:
http://www.codeproject.com/Articles/8825/Object-Oriented-Programming-In-VB-NET

"In VB.NET, classes and other data structures for a specific purpose are grouped together to form a namespace. You can use the classes in a namespace, by simply importing the namespace. The Imports keyword is used to import a namespace to your project. .NET framework provides a rich set of built in classes, grouped together to various namespaces. In this lesson, we are using the System namespace. Import the System namespace (already available in .NET)."



Indeed, namespaces help us organise our code. Say, for example, I need a class called "Form". Not the Windows Form, something else for a production plant. How do I distinguish two classes called Form?! Here namespaces come.


Try to create a new project in VB, name it, e.g., Production, and create a new form, say, Form 1. Go to designer class, it states:
Partial Class Form1
    Inherits System.Windows.Forms.Form

Open in new window


So, form1 belongs to System.Windows.Forms.Form namespace.

Now add a new class Form.

    Public Class Form

    End Class

Open in new window


No problems with that. But to make it even more unic you may add it to a Namespace:
Namespace ProductionClasses

    Public Class Form

    End Class
End Namespace

Open in new window


In C# it is done automatically. Later you will need to reference your Form class using a namespace.

See the tutorial above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Navneet.Net Full Stack DeveloperCommented:
Hi!

Every Namespace is a unique signature in itself
for example

Namespace Mubro.JLSQLBrowser.Controls.MyClass
is different from
Namespace Navneet.JLSQLBrowser.Controls.MyClass

Whereas
Namespace Mubro.JLSQLBrowser.Controls.MyClass
is different from
Namespace Mubro.JLSQLBrowser.Controls.MyClass
are same class.


Say you create two assemble (Namespace MyControlsAssembly) having your new control 'MyNewControl'
Now if you also have another project (Namespace MyFormAssembly)  new Control named same 'MyNewControl'

So if you have a Project and you add both these controls, then your project will give you compile error as it's confused which to refer in that case you have to mentions with it full Namespace at import level
using MyFormAssembly;
or
inline
MyFormAssembly.MyNewControl ctr = new MyFormAssembly.MyNewControl();


Thanks!
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.