Visual Basic.NET





Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to  Visual Basic pre-2002, it is not the same technology,

Share tech news, updates, or what's on your mind.

Sign up to Post

How can i access the type Attributes directly if my XmlNode holds the below xml file.

i tried the following with no luck
dim elementPath as String = "ns:RequestedAddr/ns:type"
dim elementPath as String = "ns:RequestedAddr/type"
dim elementPath as String = "RequestedAddr/type"

Dim myNode As XmlNode = node.Attributes(elementPath)

I need to check if the node / Attribute exists to avoid null exceptions

        <RequestedAddr type="unknown">12099925140</RequestedAddr>
        <DestAddr type="e164">+12099925140</DestAddr>
        <RoutedAddr type="national">2099925140</RoutedAddr>
        <CallingPartyRoutedAddr type="national">2099313552</CallingPartyRoutedAddr>
        <CallingPartyOrigAddr type="national">2099313552</CallingPartyOrigAddr>

Open in new window

Free Tool: SSL Checker
LVL 12
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Simple question for a newbie about concatenates. I have three text boxes on a form. txtboxFirstName.Text  txtboxLastName.Text  txtboxEmailID.Text .  The end result I am looking for is to concatenate the third text box with values from the first two text boxes. I have a very simple piece of code in my txtboxFirstName with the following.

txtboxEmailID.Text = txtboxFirstName.Text + txtboxLastName.Text

The result of this gives me the following output in the txtboxemailID.text:  JaneDoe

So far this works as I need it to. Now what I want to do is at the end of the last name add our email address so the end result I am looking for in the txtboxEmailID.Text is :

My thought was to add another text box called txtemaildomain and have this on the form load:

txtemaildomain.Text = ""

Then simply hide that textbox on my form and do the following: txtboxEmailID.Text = txtboxFirstName.Text + txtboxLastName.Text + txtemaildomain.Text

What is the proper syntax or more efficient way to add the address to the end of the last name? Thanks in advance.
For Next in

I would like to run this 7 yimes
How do I take a DataTable  and create a view that skips the first 5 columns in
Or actually removes the first 5 columns form the datatable

  Using dt As New DataTable("Leads")

' blah... blah... blah...

End Using
In my code below... the file is created with double quotes in text fields.
How do I suppress that?

If CBool(createCSVFile) Then
    Dim writer As New CsvWriter(Path & "\Exports\" & Trim(Left(FileName, 50)) & ".csv", ",", Encoding.Default)
    writer.WriteAll(dt, True)
End If

Open in new window

Good afternoon experts. Newbie here to I created a form with ms visual studio 2017 community addition. The form contains a datagridview that connects to a sql database (sql 2008). On my form I have several text boxes that are used to enter data which then populates my grid via a "add record" button. The connection to my sql database is handled in a class I called SQLControl.vb (if that matters). Listed below is my code for the add record button. So far everything works great and now what I need is a check to prevent duplicate data from being entered so I am looking for a check against my text box and datagridview. The field (not a primary key) I would like to validate against is called EMPL_ID (employee id). I don't know how to accomplish what I'm sure is a simple task.

Here is the code behind the button:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If txtboxEmplID.Text = "" Or txtboxLastName.Text = "" Or txtboxFirstName.Text = "" Or txtboxEmailID.Text = "" Or txtboxSupervisor.Text = "" Or txtboxSupervisorID.Text = "" Or txtboxManager.Text = "" Or txtboxManagerID.Text = "" Or txtboxSupervisorEmail.Text = "" Or txtboxMgrEmail.Text = "" Then
            MsgBox("All Fields Are Required", MsgBoxStyle.Information)
            Exit Sub
        End If

        'Add SQL Params & Run The Command
        SQL.AddParam("@Empl_ID", txtboxEmplID.Text)
        SQL.AddParam("@Last_Name", txtboxLastName.Text)
Hi. I am trying to search a datagridview using a textbox. As I type into the textbox, I want it to gradually generate the word. Thanks in advance, Here is my code so far

Dim lines() As String = My.Computer.FileSystem.ReadAllText("C:\Users\Sean Travers\Downloads\clubituplesswasteofmoney1\clubituplesswasteofmoney\orderdata.txt").Replace(vbLf, "").Split(vbCr)
    Private Sub txtcustomername_TextChanged(sender As Object, e As EventArgs) Handles txtcustomername.TextChanged
        Dim searchedlines(-1) As String 'create an array to fill with terms that match our search

        If txtcustomername.Text = Nothing Then
            datapopulate(lines) 'just populate the datagridview with our text file array
            For Each line In lines
                If line Like "*" & txtcustomername.Text & "*" Then 'check if anything in our search matches any of our terms
                    ReDim Preserve searchedlines(UBound(searchedlines) + 1) 'resize the array to fit our needs
                    searchedlines(UBound(searchedlines)) = line 'add the matched line to our array
                End If
            datapopulate(searchedlines) 'populate the datagrid with our matched terms array
        End If
    End Sub
    Private Sub datapopulate(ByVal mylist)
        Dim dgrow As DataGridViewRow
        Dim dgcell As DataGridViewCell

        dgvorders.Rows.Clear() 'clear the grid

        For Each line As String In mylist 'do the same …
I am good in, very little practice in C#, JAVA. I want to start building a website that will require customers in various location to login and be able to view and update their own pages. Client's of my customers should also be able to create a simple profile, view item and also make selections of items for further purchase.

the site may not accept direct payment

Is VB,NET sufficient for this or i need to upgrade my JAVA or C#

Which language should be the best for this


I'm using 2013. I'm trying to select a item from a DataGridViewComboColumn. I have jet all data charged, and manually working, but I need select some ones by code. Any idea?

For example, I have a list o ten names (as display member) and each ones with an id (as valuemember). I want to select by code an id to show the name.


How do I get the content from an HTTPclient POST in VB.NET?

Here is what I have tried so for in my Winform Application.  In this example, I am trying to send 2 values, and I want to send the result to "responseString".
        Dim client As HttpClient = New HttpClient

        Dim values As New Dictionary(Of String, String) From {{"Input1", "hello"}, {"Input2", "world"}}
        Dim content As Object = New FormUrlEncodedContent(values)
        Dim response As Task(Of HttpResponseMessage) = client.PostAsync("", content)
        Dim responseString As String = response.Content.ReadAsStringAsync

Open in new window

I am currently getting my error at "response.content", probably becuase I am not sure how to handle a "Task(Of HttpResponseMessage)":
Dim responseString As String = response.Content.ReadAsStringAsync

Open in new window

BTW, the above code is what I cobbled together from websearches, but if I the amount of data expected is relatively small, perhaps it would be easier to come with a solution that isn't asynchronous?
Train for your Pen Testing Engineer Certification
LVL 12
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

I'm wondering why the following query string works great if I assign an explicit
value to  c.item_ID, as so:

 Dim connectionString2 As String = "Server=SQLSERVER;Database=DB;Trusted_Connection=True;"
        connection2 = New SqlConnection(connectionString2)
        MsgBox("heres the ItemID from above: " + MyItemIDValue)
        Dim myparam2 As New SqlParameter("@itemID", MyItemIDValue)
        MsgBox("just assigned: " + MyItemIDValue + " to @itemID...hopefully")
        Dim queryString2 As String = "SELECT TOP 1 a.product_group_id as 'PRODUCT_GROUP',b.product_group_id as 'INV_LOC',
                            c.default_product_group AS 'INV_MAST',c.item_id as 'INV_MAST'
                            FROM product_group a
                            inner JOIN inv_loc b
                            ON a.product_group_id = b.product_group_id
                            inner join inv_mast c
                            ON c.default_product_group = b.product_group_id
                            WHERE c.item_id = 'STB 850077'"
        '        Dim queryString2 As String = "SELECT top 1 * from inv_mast
        'WHERE item_id = [b]@itemID[/b]"

        Dim command As New SqlCommand(queryString2, connection2)
        command.CommandText = queryString2
        command.CommandType = CommandType.Text
        command.Parameters.Add("@itemID", SqlDbType.VarChar)
        command.Parameters("@itemID").Value = MyItemIDValue


Open in new window


In visual studio when write: ' os [space] appears '' aSender As Object,'.
1 - Write ' to comments
2 - Write os word
3 - Press KEY space
4 - Appears aSender As Object, instead os word

best regards

I'm using visual studio with access, is there a way to prevent 2 users from editing the same record? Like if user 1 opens a record while user 2 already has it open, is there a way that user 1 gets a warning message that he can't edit the record?

Thank you for the help.

Hello. I am fairly new to programming and I am learning I am currently using visual studio 2017 community. I created a form the contains entry fields along with a dataviewgrid that stores the information based on what was entered in the text boxes. The data is being stored on a sql database (2008). My form has two buttons. An add new button and save button. Basically I enter info in my text boxes then hit the add button, This populates my data grid. The issue I am having is with my save button. When I press the save button I received the following error:

System.InvalidOperationException: 'Update requires a valid updatecommand when passed datarow collection with modified rows. I don't know how to correct this? Below is my simple code if it helps.

Public Class Form1
    Private Sub CamTagIssueBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles CamTagIssueBindingNavigatorSaveItem.Click

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ControlledItemsDataSet.CamTagIssue' table. You can move, or remove it, as needed.

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Is there anychange in the db connection string when connecting from vb. net to sql server dayabase instance  when clustering is done on the database.

Greetings Gurus:

I'm working on a softball league and need to pass an array or table of team numbers (int) from my code to a stored procedure as a parameter. The stored procedure will use this data in a WHERE intTeam IN (<array>|<table>). Currently, I am executing the procedure for each team. There may be as many as several hundred teams.

The stored procedure currently looks like:
ALTER PROCEDURE [dbo].[up_s_StandingTotalSeasonalRuns] 
	-- Add the parameters for the stored procedure here
	@intTeamNumber			int
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

    -- Insert statements for procedure here
					FROM sys.objects
					WHERE object_id = OBJECT_ID(N'#TeamScores'))		
		DROP TABLE #TeamScores

		SELECT		fkintTeam1 AS intTeam,
					SUM(intScore1) AS intTeamVsTeamTotal
			INTO		#TeamScores
			FROM		Schedule
			WHERE		fkintTeam1 IN
			GROUP BY	fkintTeam1


		SELECT		fkintTeam2 AS intTeam,
					SUM(intScore2) AS intTeamVsTeamTotal
			FROM		Schedule
			WHERE		fkintTeam2 IN
			GROUP BY	fkintTeam2
			ORDER BY	intTeam

	SELECT		intTeam,
				SUM(intTeamVsTeamTotal) AS intTeamVsTeamTotal
		FROM		#TeamScores
		GROUP BY	intTeam

Open in new window

The procedure reads schedule records which have the following columns:
	[intScheduleId] [int] IDENTITY(1,1) NOT NULL,
	[fkintFieldNo] [int] NULL,
	[dtPlay] [datetime] NOT NULL,
	[fkintTeam1] [int] NULL,
	[intScore1] [int] NOT NULL,
	[fkintTeam2] [int] NULL,
	[intScore2] [int] NOT NULL,
	[blnGamePlayed] [bit] NOT NULL,
	[blnByeWeek] [bit] NOT NULL,
	[blnHoliday] [bit] NOT NULL,
	[blnMakeUp] [bit] NOT NULL,
	[blnDoubleHeader1] [bit] NOT NULL,
	[blnDoubleHeader2] [bit] NOT NULL,
	[dtCreated] [datetime] NOT NULL,
	[dtUpdated] [datetime] NOT NULL,
	[tsValue] [timestamp] NOT NULL

Open in new window

Any assistance you might provide is most appreciated.

Much thanks,
David Bach
When building code, I am not seeing my changes.  I've changed a simple Text Header on a page and ran the code and it does not change.
I've cleared my cache, restarted, tried a clean build and am at a loss as to what cold be causing this.

We have tested and this is only happening on React JSX pages.  It doesn't look like Webpack is compiling the changes but rather old code.
I am using VB.Net and Visual studio 2015. I have an application with a Access database table (.accdb) that is nearing the 255 field limit. Therefore, I have split the table into two tables and created a nested Parent/Child relationship between the two tables in an attempt to overcome this limitation.

The problem is that I cannot update the two tables when the Save button is pressed. The TableAdapterManager will update the Parent table, but not the Child table.

Has anyone had this problem and found a solution? I have seen many other asking the same question, but I have not seen any solutions. Below is the code for the Save button.

 'Save Button
    Private Sub ParentTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ParentTableBindingNavigatorSaveItem.Click

    End Sub

Open in new window

Hello Again Experts.

I am trying to return a single value from a data table using the following code:
    Private Sub Calc_PAT()
        ' Calculate and Update Total/Match Points and Running Totals after each Match
        ' Note that table Scoring has been replaced with a simple String array (SL_P2W), and
        ' a new table called Scoring which contains what is needed for calculating Match Points.
        ' The following SQL command is an example of a query that would return the number of
        ' Match Points given to the loser with a Skill Level of 3, and their Total Points was 20:
        Dim command_builder As New OleDbCommandBuilder(OleDbDataAdapterMatches)
        Dim LsrMP As Int32 = 0, WnrMP As Int32 = 0, LsrNo As Int32 = IIf(TN = 1, 2, 1)
        Dim LoserSL As Int32 = CInt(PT(SK, LsrNo).Text)
        Dim SL_Clmn As String = "SL" & CStr(LoserSL)
        Dim LoserTP As Int32 = CInt(PT(MP, LsrNo).Text)
        Using con As New OleDbConnection(OleDbConnection.ConnectionString)
            Using cmd As New OleDbCommand
                cmd.Connection = con
                cmd.CommandText = "SELECT DISTINCT ? FROM Scoring GROUP BY ?, " _
                  & SL_Clmn & " HAVING LS = " & PT(MP, LsrNo).Text & ";"
                cmd.Parameters.Add(New OleDbParameter("@Param1", SL_Clmn))

Open in new window

Free Tool: ZipGrep
LVL 12
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


I'm working with a webservice with different classes in it.

A class can look like this for example:
    Public Class TekniskInformation
        Implements IExtensibleDataObject, INotifyPropertyChanged

        Public Sub New()

        Public Property ExtensionData As ExtensionDataObject
        Public Property Fordonsidentifikation As Fordonsidentifikation
        Public Property VardenPerDrivmedel As Drivmedel()

        Public Event PropertyChanged As PropertyChangedEventHandler

        Protected Sub RaisePropertyChanged(propertyName As String)
    End Class

Open in new window

The class of Fordonsidentifikation then looks like this:
  Public Class Fordonsidentifikation
        Implements IExtensibleDataObject, INotifyPropertyChanged

        Public Sub New()

        Public Property FordonskategoriEU As String
        Public Property ModellNr As Integer?
        Public Property Handelsbeteckning As String
        Public Property GruppNr As Integer?
        Public Property Fordonsslagskod As Integer?
        Public Property Fordonsslagsklass As String
        Public Property Fordonsslag As String
        Public Property RegNr As String
        Public Property Fordonsar As String

Open in new window

Hi all.

I'm having an issue populating a datagridview control when my form loads. My code is below. I want to populate the datagridview control when the form loads. The form is opened when the end user clicks the "Edit" button in another form. I even tried moving DataGridView1.DataSource = GetDataTable_Tags() to the "Shown" event and it still does not populate the datagridview control. The only way it loads if I put DataGridView1.DataSource = GetDataTable_Tags() in the Click event of a button. Any ideas what I'm doing wrong?

Thank you in advance.

Code to open the form:
Private Sub EditDetailsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditDetailsToolStripMenuItem.Click
Dim GridRow As DataGridViewRow = DataGridView1.CurrentRow
        Dim frm As New DocumentEdit
        frm.menuID = GridRow.Cells.Item("MenuID").Value

    End Sub

Open in new window

Private Sub DocumentEdit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.DataSource = GetDataTable_Tags()
    End Sub

Private Function GetDataTable_Tags() As DataTable

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand

        con.ConnectionString = "Data Source=myServer;Initial Catalog=myDB;Integrated Security=True"


        cmd.Connection = con

        cmd.CommandText = "SELECT Tags FROM Menu WHERE MenuID = @MenuID"
        cmd.Parameters.AddWithValue("@MenuID", menuID)

        Dim sda As

Open in new window

Using the Uri object to return a list of domain found in the  string

I need to find if Uri (or related .NET object) can return 2 of 3 domains when it parses this string:";

I would be okay if it returned:


How can I do this with Uri or some other .NET object?

I have a web application built in The home page is "main.aspx". I have x3 other websites that are directing traffic to the this website...the redirects are pointed to the main.aspx page. How can I capture which site the traffic is coming from? I'm thinking something with the headers. I would really like to capture the referring url or something that is unique.
Hi Experts,

I am trying to debug my program.

How can I determine what database is being used by a Data Grid View (dgv) control in run time?

My Data Grid View (dgv) control is dgvMaterials.

When my form is loaded and I check the values of dgvMaterials in the Immediate window using ?dgvMaterials, I get this output:

    AccessibilityObject: {ControlAccessibleObject: Owner = System.Windows.Forms.DataGridView}
    AccessibleDefaultActionDescription: Nothing
    AccessibleDescription: Nothing
    AccessibleName: Nothing
    AccessibleRole: Default {-1}
    AdjustedTopLeftHeaderBorderStyle: {DataGridViewAdvancedBorderStyle { All=NotSet, Left=OutsetDouble, Right=Outset, Top=OutsetDouble, Bottom=Outset }}
    AdvancedCellBorderStyle: {DataGridViewAdvancedBorderStyle { All=Single, Left=Single, Right=Single, Top=Single, Bottom=Single }}
    AdvancedColumnHeadersBorderStyle: {DataGridViewAdvancedBorderStyle { All=OutsetPartial, Left=OutsetPartial, Right=OutsetPartial, Top=OutsetPartial, Bottom=OutsetPartial }}
    AdvancedRowHeadersBorderStyle: {DataGridViewAdvancedBorderStyle { All=OutsetPartial, Left=OutsetPartial, Right=OutsetPartial, Top=OutsetPartial, Bottom=OutsetPartial }}
    AllowDrop: False
    AllowUserToAddRows: False
    AllowUserToAddRowsInternal: False
    AllowUserToDeleteRows: False
    AllowUserToDeleteRowsInternal: False
    AllowUserToOrderColumns: False
    AllowUserToResizeColumns: True

Open in new window

Screen shot of MyPlayers formHello Experts.
I'm having a little trouble making an UPDATE to one of my data tables. In this case, it's for adding a picture.   No error is being displayed, so I'm guessing the syntax for the UPDATE is okay, but there's probably a step missing which needs to come afterwards. In fact, the image is being shown in the PictureBox, just not being written to the Roster table. Let me explain...

To simplify, let's say that I have two tables; one is called Roster and contains all data for league players. This includes their ID, name, team, and other fields including their profile picture.

The second table is called "MyPlayers" and contains references to all the players on MY team. Some of the data is pointing to Roster columns, and other data is completely local to the table, such as email address, phone and more detailed stats gathered during game play. The form also has a place for the player's picture and I would like for users to be able to click on the "Load Picture" button from that screen and have it stored on the Roster table.

Here's the code I've got so far:
    Private Sub btnDataRosterPicture_Click(sender As Object, e As EventArgs) Handles btnDataRosterPicture.Click, btnMyPlayersPicture.Click
        Dim dlg As New OpenFileDialog
        Dim Width As Double = 90
        Dim Hight As Double = 120
        If dlg.ShowDialog = DialogResult.OK Then
                Dim toFile As Stream = File.Open(Application.StartupPath & 

Open in new window


Visual Basic.NET





Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to  Visual Basic pre-2002, it is not the same technology,