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

In, how can I create recordset from multiple datatables?  For example, if I want to use a left join between two datatables to see all records in one datatable that don't have a matching record in another datatable, how would I do that?  I know that if I create a connection object to a SQL Server or Access database then I can then use a command object based on that connection object to specify a SQL statement that includes a left join between two tables in that remote database.  Can I create a connection object to connect to a local dataset resident in the memory of the .net application?  If so, can I base a command object on that connection object and specify the names of datatables in that dataset in a SQL statement of that command object?
Exploring SQL Server 2016: Fundamentals
LVL 12
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Hi all.

I have a chart that displays sales stages and the count for each sales stage. I want to be able to allow the end user to double click the X-axis label, which is the sales stage, and save that value in a variable. Unfortunately, I haven't been able to do so. Below is some of the code, I'm trying to show it in a messagebox for now, I've been playing with but unable to get it to work. I basically want to get the axislabel when it's double clicked.

Private Sub Chart1_MouseUp(sender As Object, e As MouseEventArgs) Handles Chart1.MouseUp
 Dim HTR As HitTestResult
       HTR = Chart1.HitTest(e.X, e.Y)
Dim h As HitTestResult = Chart1.HitTest(e.X, e.Y)
If h.ChartElementType = ChartElementType.AxisLabels Then
Dim dp As DataPoint = Chart1.Series("Stages").Points(h.PointIndex)
End If
 End Sub

Open in new window

I was able to get this to work by clicking the datapointlabel instead of the axislabel, but ultimately I would like it to work for the axislabel. See code below:

Private Sub Chart1_MouseUp(sender As Object, e As MouseEventArgs) Handles Chart1.MouseUp
Dim SelectDataPoint As DataPoint
Dim h As HitTestResult = Chart1.HitTest(e.X, e.Y)
If h.ChartElementType = ChartElementType.DataPointLabel Then
SelectDataPoint = CType(h.Object, DataPoint)
End If
 End Sub

Open in new window

I migrated vb6 to using the vs2008 wizard and it works fine But some controls are not visible on form.
 I can see them on control list in properties window but can not get them to be seen on the form in design time.
what am I missing?...
Hi experts, I am using Microsoft.Office.Interop.Owc11.dll in my project
some properties dont work as expected and im looking for solutions:

ReportForm.Spreadsheet11.ActiveSheet.Range("a1:" & Chr(intReportColumns - 4 + 65) & 1).MergeArea.HAlignment = OWC.SheetHAlignEnum.ssHAlignCenter


Thanks in advanced

I use the following code in my Excel Addin to create a taskpane when the addin loads.
It works well in Excel 2007 and 2010 but badly in Excel 2013 and 2016. In 2013 and 2016
the taskpane disappears or causes errors.

Is there a better way that I should be doing this in the later versions of Excel?

Public Class ThisAddIn

    Private oTaskPane_Tables As TaskPane_Tables
    Public WithEvents Tables_CustomTaskPane As Microsoft.Office.Tools.CustomTaskPane

    Private Sub ThisAddIn_Startup() Handles Me.Startup

            oTaskPane_Tables = New TaskPane_Tables
            Tables_CustomTaskPane = CustomTaskPanes.Add(oTaskPane_Tables, "Tables/Views")
            Tables_CustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft
            Tables_CustomTaskPane.Width = 330

        Catch ex As Exception
        End Try
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub
    Public ReadOnly Property oTABLES As TaskPane_Tables 'gives access to alter controls on TaskPane
            Return oTaskPane_Tables
        End Get
    End Property

    Private Sub Tables_CustomTaskPane_VisibleChanged(sender As Object, e As System.EventArgs) Handles Tables_CustomTaskPane.VisibleChanged
            Globals.Ribbons.Ribbon1.ToggleButton_Tables.Checked = Tables_CustomTaskPane.Visible

        Catch ex As Exception
            MsgBox(ex.Message & " 

Open in new window

Im looking for a way with VB.NET or something similar to keep a particular webpage refreshing in the users chosen web browser on a timer to basically prevent a timeout where they got logged out and are required to log back in to a web portal from an external provider. Is there a way to tell a web browser application to refresh a tab externally either by the url or the name of the tab ? Im thinking that using a vb app to browse the website wouldn't work because its outside the browsers context where the user authenticated and would not achieve what im after. Any ideas or a completely different approach maybe ?
I would like to add a filter for a Gridview Control in VB.Net 2012.  What is the best solution in doing this?

Thank you!
Why might I getting this error. I am trying to connect to a DB from a console application and get this error.
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Imports System.Data.Entity

Module Program

    Dim people As IEnumerable(Of Person) = New List(Of Person)

    Sub Main(ByVal args As String())
        Using context = New EFDbContext() '<--- Error here
            Dim repo As ITestRepository = New EFRepository(Of EFDbContext)(context)

        End Using

    End Sub
End Module

Public Class EFDbContext
    Inherits DbContext

        Public Sub New()
        End Sub

    Public Property People As DbSet(Of Person)

End Class

Open in new window

Concurrency problem.
I’ve written code to check if a record has been updated before I do an update, if the record has changed then I get the index of the field/s and compare that to my current edits, if my edits are not equal to the already edited field I proceed with the update, if they are equal I display a msgbox and exit the edit.

How can I override the Concurrency error and continue with the update?
I’ve seen references to “OverwriteChanges”, but can’t find any information on its usage.
Thanks in advance

VB 2017
" Public Function FunAddEditRecord(ByVal AddEdit As String) As String" is where the edit/update is.

Public dsDdsMrpDatbaseWorking As New DataSet
Public daDdsMrpDatbaseWorking As OleDb.OleDbDataAdapter

Open connection:
sqlString = "SELECT * FROM PartItem"
daDdsMrpDatbaseWorking = New OleDb.OleDbDataAdapter(sqlString, DDS_MRP_DatabaseConnection)

daDdsMrpDatbaseWorking.Fill(dsDdsMrpDatbaseWorking, "PartItem")
close connection
EditRecord = dsDdsMrpDatbaseWorking.Tables("PartItem").Rows(FrmMain.uint16PartSearch)
EditRecord(ItemIndex) = some value
'Update the database
daDdsMrpDatbaseWorking.Update(dsDdsMrpDatbaseWorking, "PartItem")
Im using chr function in my code but it doesnt seem to work the same like in vb6.
I searched and read but still it doesnt seem to work I get chrw(1) instaed of a:
            Dim c1 As Char = Convert.ToChar(1)
what am I doing wrong ?
Become a Microsoft Certified Solutions Expert
LVL 12
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

I need to translate a column number at runtime to an excel range address in
is there any function I can use instead of writing my own?
Hello experts,

There is an issue in printing records in sub-report. I have explained my query in detail in attached file.

Please help.

D Patel
I have two workbook.

Each workbook will have different sheets.

When both workbook sheets are the same, then it should check every individual cell of both the sheet.

let us imagine, both the sheet start range A20:KJ20

Sheet1 ==> A21 cell value is "12"

Sheet2 ==> A21 cell value is "14".

the above value is different, then it should show the difference in various color in "Sheet1"

I have done some code below.

But, worksheet not showing the range.

 Dim varSheetCurr As Object
                            Dim varSheetPrev As Object
                            Dim strRangeToCheck As String
                            Dim iRow As Long
                            Dim iCol As Long

                            strRangeToCheck = "A21:IV65536"
                            ' If you know the data will only be in a smaller range, reduce the size of the ranges above.

                            varSheetCurr = Worksheets("Sheet2").Range(strRangeToCheck) 
                            varSheetPrev = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.

                            For iRow = LBound(varSheetCurr, 1) To UBound(varSheetCurr, 1)
                                For iCol = LBound(varSheetCurr, 2) To UBound(varSheetCurr, 2)
                                    If varSheetCurr(iRow, iCol) = varSheetPrev(iRow, iCol) 

Open in new window

Hi Everyone,
I'm facing a problem says "There is no row at position 0." ..... I got this code from this site  How To Perform Paging with the DataGrid Windows Control by Using Visual Basic .NET
Really it's so helpful and with some few modifications , i got rid of some problems like 'There is no row at position 0.' but it appears randomly ....
I will have to display all my code to facilitate the sight  
Public Function GetData() As DataView
        'Cartons > 0 And
        Dim SelectQry = "SELECT BillInfo.InvoiceNo as [رقم الايصال],
                                    ProductSold.SoldDate as [تاريخ البيع],                                    
                                    BillInfo.CustomerName as [اسم العميل],
                                    ProductSold.ProductCode as [كود الصنف], 
                                    ProductSold.ProductName as [اسم الصنف],
                                    ProductSold.Price as [سعر التكلفة],
                                    ProductSold.Category as [اسم الباكية], 
                                    ProductSold.AVP as [الكمية المتاحة عند البيع], 
                                    ProductSold.SellPrice as [سعر البيع],
                                    ProductSold.SoldPackets as [الكمية المباعة], 
                                    ProductSold.TotalAmount as [الاجمالى المبيعات من 

Open in new window

Hi experts
I have a listview in its multiselect and checkbox selection. How do I get the selected item without looping through the selecteditems collection?
I need the last checked item

I've done some refactoring a database, separating billable (claim entries) from non-billable (time/expense entries). Initially all these records were in a single table . No surprise a lot of regressions have occurred in part because of these combined entries.
What I need assistance with is with an approach for the payroll report stored procedure. Currently it gathers all the information from the tbl_claims table. I now have 3 tables, tbl_claims, tbl_expenses and tbl_hours. I'm needing to get this information back out of the database and not sure of an approach that would be decent as well as not hindering performance. Users will run these reports for up to 12 months in which there could be 100k rows returned.
My thoughts were to create temporary tables and 3 separate stored procedures and then from VB.NET code make a call to each stored proc as needed to obtain all the results. I'm not really sure how to approach this as mentioned. I've attached the stored procedure as well as the CREATE TO T-SQL code. I'm using MS SQL Server 2016 Enterprise edition.

Hello Experts.

I'm looking for some creative ideas on how I might go about adding drill-down capability to my databound forms. Allow me to explain...

Let's say that my hypothetical project is for managing a local sports league, and includes three databound tables and corresponding forms for entering / updating records:
  • Players
  • Teams
  • Schedule

As you can imagine, some of the data in these tables are related. So, the Players table would have a field to specify which team they are on. The Teams table would have a field to specify the Captain and their Player ID. The Schedule table would have the two Team IDs that are competing each week.

I would like to be able to make the TextBoxes which have a direct relationship clickable, with the action being to display the correct Form and record. So, if I'm working within my Players Form, and I want to have a look at the details about their Team, I could just click that field and the Teams form would be shown for that player's team.

Hopefully, that's fairly clear. Any thoughts how I might go about making this a reality?


I have three tables that I need to compare and use a checkbox

Table one - list of all the stores
Table two - list of managers
Table three - list of store assignments

Table three is the one that needs to be able to update / add / delete

I would like a list of all the stores when a manager is picked (dropdown list) in one gridview, and the ability to check (assign a store to) and uncheck (remove an assigned store).  Table one and two are static and will never change.

Any help would be great!  I am stuck on how to do the SQL statement and the code for the gridview

I am trying to make a Microsoft word document that allows users not to edit content once the content controls are removed. My plan to do this was by restricting the editing to only filling in forms and then creating a code that removes the content control anywhere that there is text value. I am new to VBA and cant get the code to work properly. I can get it to remove the content controls when they are empty but when I try to remove them with content they do not disappear. I have attached the document that I cant get to work.

If anyone can help me that would be fantastic!


Become a Certified Penetration Testing Engineer
LVL 12
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Using Visual Studio 2015 on Server 2008R2, coding in VB.Net.
Any of my existing projects now give the message
"Error while trying to run project. The Visual Studio Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. "
The projects still compile, and I can run the .exe, but I can't debug or step though code.
Any ideas?

VS2015 Error
I have images saved in different Idproduct folder. Each image will be linked to a third-party website with the same image. I followed  the expert Snarf0001's  example. But has error saying 'i' is not declared. It may be inaccessible due to its protection level.
Below is the coding:
 <a href="<%=productsku%>&imagelocation=images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %>"><img width="60px" height="60px" src="images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %></a> 

Open in new window

Please advise! Thank you!

I have found the following code to render an SSRS via a SSIS script. This script works as it is intended, e.g. saves the rendered report to disk.

But I would like to send the rendered report as an email attachment, without saving it to disk. Please could someone help? I have tried to render it to a memory stream but I can't quite get it to work.

Thanks, Greg

 Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
        Dim loRequest As System.Net.HttpWebRequest
        Dim loResponse As System.Net.HttpWebResponse
        Dim loResponseStream As System.IO.Stream
        Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
        Dim laBytes(256) As Byte
        Dim liCount As Integer = 1
            loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
            loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
            loRequest.Timeout = 600000
            loRequest.Method = "GET"
            loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
            loResponseStream = loResponse.GetResponseStream
            Do While liCount > 0
                liCount = loResponseStream.Read(laBytes, 0, 256)
                loFileStream.Write(laBytes, 0, liCount)
        Catch ex As Exception
        End Try
    End Sub

Open in new window

I hope there is someone out there who can help.  I am in the middle / end of developing a program for my accountant.  we are trying to prepare for the MTD which is coming in 2019.  This program is meant only for the accountants present customers so this is not a huge money making scheme just trying to make the job easier. I have approached a company called Yodlee to be the middle man to connect to the clients banks with a bank feed API etc.  The thing is now we are now wanting to take it out of the sandbox environment but need to find a less expensive option as this project was meant to make the job easier not make lots of money.

Is there other options out there for bank feeds? If so can someone help? Are they UK compatible?

Thanks in advance
Hi All,

I want toggle show selected data.
Please see below code.

  Private Sub btnInvoiceYangDibayar_Click(sender As Object, e As EventArgs) Handles btnInvoiceYangDibayar.Click

        Static blnFilerInvoice As Boolean = False

        Dim dataView As DataView = dtTDFAKTUR.DefaultView

        If Not blnFilerInvoice Then
            dataView.RowFilter = "Pilih = 1"

            dgvFaktur.DataSource = dataView
            dgvFaktur.DataSource = dtTDFAKTUR            
        End If

        blnFilerInvoice = Not blnFilerInvoice

    End Sub

Open in new window

It works when blnFilerInvoice  = false, but not when blnFilerInvoice = true

Scenario, there are 10 rows, I selected 1 rows, when the first time press the button, it should just show just 1 row selected.
And I press again, the it should show 10 rows again.

What is wrong with my code ?

Thank you.
Hello.  I want to use SQLite in my VB.NET application.  In my application, the user opens a file and the database connection is kept open until the program is shut down, or another file is opened.  A major requirement I have, however, is that these files should be password protected so that they can only be opened by my application.  I have found some options for encrypting SQLite files (e.g. SQLiteCypher), but they are a bit pricey so I'm looking for other methods to get what I need.

One alternative I thought of would just be for me to manually encrypt and decrypt files using Rijndael (I found an example on CodeProject).  That is, when the file is created within my application, it is encrypted so that it cannot be opened by any normal SQLite viewer application.  However, when the file is opened in my program, it would first be decrypted, then connected to normally.  When the connection is closed, the application would then encrypt it again.  I have done a quick test on this and it seems to work, but I am wondering if I am missing, or not considering, something.  Is there any reason why this idea would be ill-advised?  Thank you.


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,