Add a Web User Control Dynamically (At Runtime).

We can add a Web User Control Dynamically (At Runtime) in 2 steps.

Step 1 : Add a "PlaceHolder" in your aspx page.
Step 2 : Write the following code on page load (Code Behind).

Code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim UCDynamic As Control
    'WebUserControl.ascx : User Control path
    UCDynamic = LoadControl("WebUserControl.ascx")
    PlaceHolder1.Controls.Add(UCDynamic)

End Sub

To check a primary key exists or not in table

Use the following Query to check whether the Table does have "Primary Key" or not.

Lets assume its Employee Table here. the Query is as Follows :

Example :
    IF OBJECTPROPERTY( OBJECT_ID( '[dbo].[Employee]' ), 'TableHasPrimaryKey' ) = 1
        PRINT '[dbo].[Employee] table has a primary key.'
    ELSE
        PRINT '[dbo].[Employee] table has no primary key.'