WHAT'S NEW?
Loading...

How to use Circular Progress Bar Control


DotNetBar is a third party application use to create nice looking application because of its capability to change how it looks. There’s a lot of controls and component could be used to make your application more professional looking than usual windows form application. One control that I love to use is Circular Progress Bar, circular bar simple yet impressive design and its thrilling appearance, you can change the color how it looks like. Now, let’s give you a simple code how to use circular progress bar.

In your windows form, you need a circular progress, timer for time interval, and one button to trigger when it start.

In Timer1, this the code

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
       
        If Timer1.Interval = 5000 Then
            CircularProgress1.IsRunning = False
            Timer1.Stop()
            MessageBox.Show("done")
        End If
End Sub

In Button1:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
        CircularProgress1.IsRunning = True
        Timer1.Start()
End Sub
Once the button pressed, the circular progress bar start running until 5 seconds interval completed and shows a result “done”. That’s how very simple!

How to fix error Microsoft.ACE.OLEDB.12.0 Provider?

The most common problem encountered when we connect Windows Application into Database is an error occur Microsoft.ACE.OLEDB.12.0 Provider is not registered on the local machine. I been figure out this problem when I copy my project folder into another computer to run my program, definitely the error occur. In addition, I made a program in Visual Basic.Net 2010 in my laptop and my Database is Microsoft Access Database. What happen was, every time I copy the folder of my current project in other computer and paste it to my laptop, after a moment and try to debug the program an errors message display “Microsoft.ACE.OLEDB.12.0 Provider is not registered on the local machine”. I do not know what was happened and I didn’t made wrong when I copy my project, and I assumed that Visual Studio has already added this features. So, I try to search and search to find this problem, asking question on some forum sites, and made some modification on my code if an error occurs in my project when the program was compiled. Fortunately, many thanks for those people who helps to share their expertise to fix this problem. They recommend to install MS Access 2007 or a later version alternatively download and Install the Microsoft Access 2007 Databases Engine from the Microsoft website.

Absolutely, it works smoothly after I installed Microsoft Database Engine. Now, I want to share this to you. Hope this very helpful!

Windows Form Databinding in C# with BindingNavigator


In my previous tutorial which I used Windows Form Databinding in VB.NET to bind data and Customized BindingNavigator component as I used Buttons instead the default BindingNavigator component that enable you to Add, Delete, Update, Retrieve, and Search record.

Actually, it was already done this program before in VB.NET (see How to use BindingNavigator in VB.NET). As a challenge, I migrate VB.NET to C – Sharp (C#) to do this job where in the functions can perform to Add, Delete, Update, Retrieve, and Search record, and most probably all functions and design are almost identical in my previous tutorials. In fact, the code in C# not too far from the code of VB.NET.  However, there are some lines of code that you need to understand it well because of some instances. Let say, to Startup Form. Usually, in VB.NET, we go to Project MenuWindows Application Properties – and set Startup Form which form will be loaded first. In C#, to set the Startup Form you need to double click the Program.cs on your Solution Explorer. This code generated looks like this:

 static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmHome());
        }

To change the Startup Form, you only change frmHome name in which Form you want to load first. Note, the default name of every forms are Form1, Form2, Formn every time you add new Windows Form. It’s better to change the name of every Forms to make it readable and meaningful.

The experience I had while using C# is how to show Form. Before, I can’t find a solution how to work it because in VB is very simple to show Form. This is how:

 Form frm = new frmAdd();
        frm.ShowDialog();

You cannot do (Form1.ShowDialog()) like VB to show form. Instead, initialize first to enable to show other forms.

Those are among few line of codes might take to remember while working in C# if you are VB.NET programmers expertise.

Now, let’s explore the source code:

Code for Add New Entry:

private void btnsave_Click_1(object sender, EventArgs e)
{
  this.Validate();
  this.tblinfoBindingSource.EndEdit();
  this.tblinfoTableAdapter.Update(this.dbInfoDataSet.tblinfo);
  MessageBox.Show("New Records has been successfully saved", "Save Record",    
  MessageBoxButtons.OK, MessageBoxIcon.Information);
  this.tblinfoBindingSource.AddNew();
}

Code for Update Records:

private void btnupdate_Click(object sender, EventArgs e)
{
  this.Validate();
  this.tblinfoBindingSource.EndEdit();
  this.tblinfoTableAdapter.Update(this.dbInfoDataSet.tblinfo);
  MessageBox.Show("Records has been successfully updated", "Update Records",    
  MessageBoxButtons.OK, MessageBoxIcon.Information);
}

The code for Add and Update works in the same way as you have noticed.

Code for Delete Records:

private void btndelete_Click(object sender, EventArgs e)
{
     int x;
     string fname;
     string lname;

     x = this.tblinfoDataGridView.Rows.IndexOf(this.tblinfoDataGridView.CurrentRow);
     fname = this.tblinfoDataGridView.Rows[x].Cells[0].Value.ToString();
     lname = this.tblinfoDataGridView.Rows[x].Cells[1].Value.ToString();
     if (MessageBox.Show("You want to delete" + fname + " " + lname + " records?", "Confirm 
        Entry", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == 
        System.Windows.Forms.DialogResult.Yes)
     {
        this.tblinfoBindingSource.RemoveAt(this.tblinfoBindingSource.Position);
        this.tblinfoTableAdapter.Update(this.dbInfoDataSet.tblinfo);
        MessageBox.Show(fname + " " + lname + " " + "record has been successfully deleted");
     }
     else
     {
        MessageBox.Show("Cancelled","Cancelled 
        Entry",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
     }
}

Code for Retrieve Records:

  this.tblinfoTableAdapter.Fill(this.dbInfoDataSet.tblinfo);

Code for Search Records:

private void txtsearch_TextChanged(object sender, EventArgs e)
{
  this.tblinfoBindingSource.Filter = "Firstname LIKE '%" +txtsearch.Text + "%' OR Lastname 
  LIKE '%" + txtsearch.Text + "%'";
}

The screenshots are almost identical in my previous article. Download this source code hereIf you want to save more files online and share it to your friends, sign up for free.

How to use Binding Navigator in VB.NET


If you’re using Windows Form DataBinding to bind data to build an application quickly, this approach can do more with a less amount of code compare with traditional approach (unbound). In this tutorial, I’ll show you how to use Binding Navigator to enable to Add, Save, Delete, Update, Retrieve, and Search record in a simple way in default generated code (see related articles for unbound or traditional approach with ADO.NET as work in the same way). This is an example screenshot of BindingNavigator after the dataset
table’s drag into the Form.
Binding navigator
As you have noticed, it generates a controls where you can navigate data and displays number of rows in a table, enable to add, delete, and save quickly. In addition, BindingNavigator allows you to customize depends how it looks like. As my own opinion, I don’t like to use this control as my default view to add, delete, save, etc. to control my data, instead I use a buttons or icons in every commands. However, if you double click an ADD icon there’s no code available how the code does is. Fortunately, to add new entry the code is simple as this.

Me.TblinfoBindingSource.AddNew(), you can add this line of code in a Form Load while adding new entry so that you if the program start running you don’t need to click add button every time to add new entry. Then, put again this code in Save Button after message box display so that it will clear all textboxes and enable you to add again new entry.

To DELETE icon, the code is:

Me.TblinfoBindingSource.RemoveAt(Me.TblinfoBindingSource.Position)
Me.TblinfoTableAdapter.Update(DbInfoDataSet.tblinfo)
MessageBox.Show("Deleted")

The code for Save and Update works on the same way depends on how to manage the source code.

Me.Validate()
Me.TblinfoBindingSource.EndEdit()
Me.TblinfoTableAdapter.Update(Me.DbInfoDataSet.tblinfo)
MessageBox.Show("New record(s) has been added to the database")

The only difference is the message box show dialog if what message will appear either new records added or records has been successfully updated.

To navigate records without using default binding navigator, the code is simple as this. Just simply add a button |<  <  >  >|.

Move first record
Me.TblinfoBindingSource.MoveFirst()

Move previous record
Me.TblinfoBindingSource.MovePrevious()

Move next record
Me.TblinfoBindingSource.MoveNext()

Move last record
Me.TblinfoBindingSource.MoveLast()

To fill a record, Me.TblinfoTableAdapter.Fill(Me.DbInfoDataSet.tblinfo)can be found in the Form Load. Actually, you can omit this line of code if you wish.

The search record the code is simple as this.

Me.TblinfoBindingSource.Filter = "Lastname LIKE '%" & txtsearch.Text & "%' or Firstname LIKE '%" & txtsearch.Text & "%'"

Here are the sample screenshots:
Add New Entry
Add New Entry
Update records
Update Records
Delete Records
Delete Records
Show Records
Show Records
Quick Search Records
Quick Search Records
Source can be download hereIf you want to save more files online and share it to your friends, sign up for free.

ByVal and System keywords removed in Visual Basic 2012


If you’re using Visual Basic 2010 then migrate to Visual Basic 2012 when you noticed there’s a lot of changes happening not only the colors and icons but also the code how it will generated. In addition, the first thing that come in your mind as you used VB 2012 and view the source code, the codes become a little compare in previous version of Visual Basic.Net. However, the omitted keywords ByVal and System are optional to use. Here are the example source code in VB2010 and VB2012.

This example is in VB 2010.
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
End Sub

This example is in VB 2012.
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
End Sub

Next, we are going to create Method Name in both version to see the difference. Though, copying the code from VB 2012 to VB 2010 will automatically generates code that compatible with VB 2010. For instance, in VB 2012 were not using ByVal nor System keyword but when you copy and paste it to VB 2010 the code will change automatically with ByVal and System.

VB 2010
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        MessageBox.Show(add(5, 5))
End Sub
    Private Function add(ByVal x As Integer, ByVal y As Integer)
        Dim a As Integer
        a = x + y
        Return a
End Function

VB 2012
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
        MessageBox.Show(add(5, 5))
End Sub
    Private Function add(x As Integer, y As Integer)
        Dim a As Integer
        a = x + y
        Return a
End Function

I had been created my method name in VB 2012 without using ByVal and System keywords. Moreover, when you copy this code and paste it in any previous version, the code will automatically add ByVal and System keywords.

How Databinding works if in case to make modification on table’s columns?


In Visual Basic.Net Windows Form DataBinding and ADO.NET on how to Setup Connection Wizard to connect database access to bind data from Windows Form Application. Now, let’s take a look how it work as data passes from Windows Form to MS Access Database and how to manage Server Explorer as part of the Data connection where in database was already located.

In this tutorial, I am using VisualStudio 2012 Ultimate, if you’re using previous version is almost identical, only the colors, icons, and other options are not same as VS 2010 because of some changes made. The one I like in VS2012, you’re allow to search windows such as Toolbox, Solution Explorer, Data Source, and other windows if not visible in your default view. If you’re now using VS2012, its looks like old windows but is doesn’t measure that. Indeed, it’s faster and light weight to use compare in previous version.  Fortunately, a lot of features is now available in Visual Studio 2012.

Now, if you had already add Database using Connection Wizard, it will automatically appear your Database file (act as Dataset a local copy of your Database) in a Data Sources Windows, and at the same time on your Solution Explorer it added new objects such as your Database and Database Dataset.

Once it has already added, in Server Explorer Window also added Data Connection from your database, Server Explorer allows you to retrieve data, add, and make some modification of your entry. However, make sure to create a copy of your file to your project’s output directory during Data SourceConfiguration Wizard so that every time you run the program, it will automatically load whatever made changes on your database. Your file can be found on folder bin/Debug/your_database_name. In this option will prompt a message.
Visual Studio Data Connection Wizard
Click Yes. If you click No, the database will remain its path location where it already saved.

Did you try or mistaken not to able to drag and drop your tables or columns name using Server Explorer Window? Actually, you cannot drag because this Server Explorer serves to manage your database connection as part of your database and tables. In Data Sources Windows, you’re allow to drag whatever you want either a table or any columns to choose any of the following Textbox, ComboBox, ListBox, and Label apply on your Form.

This is how it looks your Data Sources and Server Explorer Windows.
Visual Studio Data Sources and Server Explore Windows
In Databinding, sometime it’s hard to analyze and understand where the data passes through. Next, let’s examine how data works if some modification happen in the database tables and make some changes its columns or to add/delete/modify entry. What if I want to make changes my columns name or add another fields in my table, is it possible? This a common mistakes or unseen solution by many beginner’s in VB.Net try to make modification from their tables because they don’t have enough idea to work it. Fortunately, this is how…

Once you run the program, the database file and other object are in a folder name of your project. However, we do have two (2) database file saves on the separated folder. First, is in the Name of your Project Folder and the second one is in your Debug Folder


This is how it looks.
Database in Project folder name
Database in Project folder name
And other one.
Database in Debug folder
Database in Debug folder

Now, you have an idea where the database file was located. This is the magic trick if you want to make some modification on your table’s columns or whatever you want. Do NOT make any changes on your Debug Folder where the Database was located because whatever you made is nothing happen once the program’s start running (F5). If you want to try, open your database in Debug Folder, double click and right click on the table and click Datasheet View to show, and to add some entry or columns. Then close MS Access Database and to try run your program (F5). After run, stop the programming running and try to open again your Database in Debug folder to see what happen if there’s new added data. Nothing happen, right? The current data still unchanged.

Fortunately, if you want to do any modification in your table’s columns or entry, used first Database in the Project Folder Name not in the Debug folder. Try it to assure if it is working or not. Now, whatever changes happen you made in the first database table’s columns or entry is also automatically affected in the Debug folder Database.

The only difference, modification made from Debug folder Database nothing happens and still remain unchanged.

Glimpse the difference between VS 2010 and VS2012


Glimpse the difference between Visual Studio 2012 and VS 2012 development tools. The changes provide the needs of every developer/programmer to create application more quickly and ease of use in developing sophisticated software. Now, in new features of Visual Studio 2012, capability, portability, stability, and a lot more are already in this development tools. Let’s explore and take a look the difference compare in previous VS 2010. Review related articles in Visual Studio 11, the 1st named before it called Visual Studio 2012. VS11 and VS12 are almost identical, but there’s some few changes in VS12. Here are some photos.

Visual Studio Ultimate Version Photos:

Visual Studio 2010 Ultimate
Visual Studio 2010 Ultimate
Visual Studio 2012 Ultimate
Visual Studio 2012 Ultimate
Let's look the difference between VB10 and VB12 source code:

Visual Basic 2010:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Visual Basic 2012:
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class


If you had noticed the changes in source code, in VS 2010 it used ByVal but in VS 2012 is optional.

Visual Studio 2010 Menu
Visual Studio 2010 Menu
Visual Studio 2012 Menu
Visual Studio 2012 MENU

Configure MySQL connection in VB.NET with ADO.NET

Migrate your Microsoft Access Database to MySQL Database?

Visual Basic.Net provides variety of Data Provider to work with ADO.NET depends on the needs of the projects. For instance, to store a large amount of data to your database, it’s prefer to used MySQL, Oracle, and MSSQL because MS Access Database only provides limited features compare other Databases. Fortunately, All Data Providers works on the same way because if you know how to use OLEDB Provider also you can easily work with others.

For example.

OLEDB Class
Dim da As OleDbDataAdapter
Dim cmd As New OleDbCommand
Dim conn As New OleDbConnection

MySQL Class
Dim da As MySqlDataAdapter
Dim cmd As New MySqlCommand
Dim conn As New MySqlConnection

To use MySQL Class name. Right click anywhere in your Toolbox and Choose Items

Add New .Net Components

It will displays dialog window, the default tab is .Net Framework Components. Locate MySqlCommand, MySqlConnection, and MySqlDataAdapter.


Choose Toobox Items Components
Then, click OK.


Now, just above Public Class Form1 import class name Imports MySql.Data.MySqlClient.

To setup the connection string.

connString = "server=localhost;user id=root;password=123;database=dbinfo"

connString a variable name that holds your data provider connection, in server provider you can set localhost as number 127.0.0.1 because were both identical. If you don’t have password, let empty and lastly, your database name.


Your code looks like the following.

Imports MySql.Data.MySqlClient
Public Class Form1
    Dim connString As String
    Dim da As MySqlDataAdapter
    Dim ds As New DataSet
    Dim cmd As New MySqlCommand
    Dim sql As String
    Dim conn As New MySqlConnection

    Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load
    End Sub

    Public Sub myConnection()
        connString = "server=localhost;user id=root;password=123;database=dbinfo"
        conn.ConnectionString = connString
        conn.Open()
    End Sub

    Private Sub btnConnect_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnConnect.Click
        Call myConnection()
        MessageBox.Show("Opened")
        conn.Close()
    End Sub

    Public Sub retrieveData()
        Call myConnection()
        sql = "SELECT * FROM tblInfo"
        da = New MySqlDataAdapter(sql, conn)

        da.Fill(ds, "dbinfo")
        DataGridView1.DataSource = ds.Tables("dbinfo")
        conn.Close()
    End Sub

    Private Sub btnFill_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnFill.Click
        Call retrieveData()
    End Sub

End Class

The Windows Form Looks like the following.
MySQL and VB.NET Windows Form