A short tip when working with multiple database servers

If you’re working with multiple database servers at the same time (MySql, MS-Sql, Oracle, etc.) Be sure to enable only one of them if you don’t want to get errors when running applications especially in visual studio. Since multiple database servers running at the same time would make a conflict especially if they are installed on the same computer.

Also note, that if your working with databases, the usual server name would be ‘localhost’ or the computer name itself or the ip address of the computer running the server.

Tab Order in Visual Studio 2008

In this tutorial, I’ll be showing you a useful tool that would make arranging of items in visual studio easier.

The tab order. Is used to arrange the order of the visual items in your application, when you press on tab. By default, the order is dictated by which came first. Or which element you have first added on your application.

So to change that, just go to the main menu, select ‘view’->’tab order’.

Numbers would appear on the right side of each form element, something like this:

image

As you can see my elements has already been arranged, you can arrange yours by clicking on each element one after another.

Visual Inheritance in Visual C#

Here’s how you can inherit visual elements from a base form in Visual C# using Visual Studio 2008.

First, create 2 forms, one for the base form and one for the child form.

On the solution explorer on the upper-right pane, right click on the child form and select ‘view code’

After that, you will see something like this:

image

Just change csharptesting to the actual name of your project

image

Then change MainForm to the actual name of the base form you want to use.

Then select ‘build’->’build solution’ from your main menu.

image

Notice, that your child form will now have the same visual elements as your Main form. But also note that only the Main Form is editable, you cannot edit its child forms.

Visual Inheritance in vb.net

In this tutorial, I’ll show you how you could inherit visual objects in vb.net.

Inheriting visual objects, means that you need a ‘base form’ which you will inherit from and a form which would inherit from that base form (I forgot what its called, if you know it feel free to comment)

Add up visual elements in your base form (buttons, textboxes, groupbox, tab control, etc).

Then make a new windows form which would inherit from the base form which you have just made.

After that, click on the ‘show all files’ option on your solution explorer on the upper right pane of your visual studio window.

image

Expand the Form which will inherit from the base form, then double click on the file with ‘.Designer.vb’ extension. In my case, its named Main.Designer.vb since the name of my form is Main.

After double-clicking, you would see something like this:

image

The point of interest is the one that I have highlighted, obviously.

Inherits WindowsApplication3.Form1

Now, change this line of code to fit yours.

Just change the WindowsApplication3 to the actual name of the project which you have created. The one that is on the uppermost part of the solution explorer:

image

Then change the Form1 to the actual name of the base form that you have created.

That’s it, now you won’t have to copy and paste the same visual elements to each of your forms just to have a consistency in your application. Just do the same to all of the forms that needs to inherit from a base form.

vb.net auto-suggest function

For those of you who don’t know what auto-suggest is. I won’t define it here, just open up google and begin to type some words. And you will see what auto-suggest means.

Here’s a screenshot of the mini-application that I have made which has auto-suggest functionality. As you can see, it automatically loads up items from the database as you begin to type on the textbox.

autosuggest

Doing this is easy once you know how to read data from a database. You’ll just have to use data reader to do this.

And of course, you need to activate the auto-suggest functionality on the textbox.

Change the properties of the textbox to match the one on the screenshot below:

image

The autoCompleteSource I used is CustomSource, since I’m loading the data from a database.

If you want to load it from recent places you have gone through on your system. You might want to choose file system directory.

You can also load from the sites you have visited in your browser using the AllUrl.

But if you want to load it from either the browser history or the file system directories. You can choose AllSystemSources.

For the code, I won’t show it here. But to give you an idea. You need data reader for this. Then iterate through all of the items that are on the database while the reader still hasn’t reach the end of the database table.

Auto–increment primary key in Microsoft SQL Server using vb.net

Here’s how you can add an auto-incrementing primary key in ms-sql. First, you need to add an ms-sql database as a datasource, in your vb.net application.

After adding the database.

Go to ‘view’ –> ‘server explorer’

Then select the datasource which you have added. In my case, it is ‘kyokasuigetsu.onstor.dbo’

Expand that, and you will see the ‘Tables’ folder. Select the table that you want to work with. In my case, it is the ‘prod_table’ . Then select ‘open table definition’ as you can see in the screenshot below.

image

Select the primary key of the table that you have chose. In my case it is the ‘PID’ field. 

Under  ‘column properties’. You will see the ‘Identity Specification. Expand that. And change the value of ‘Identity Specification’ to ‘yes’ by either double-clicking or just change its value from the properties pane. The (is identity) will also automatically change.

And the ‘identity  increment’ and ‘identity seed’ values will be automatically equal to one.

This means that you won’t have to insert a value to the primary key if you’re going to perform an insert query. The identity increment is the value which will be added to the primary key everytime you perform an insert query. The identity seed is the primary value of the primary key. This means that it will begin counting from 1 up to the last inserted value.

image