Update Dimensions Table for Data Warehouse in VB.Net

Private Sub btnUpdateDim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateDim.Click
Dim sqlupdatetable As String
Dim counter As Integer
counter = 0
If (btnUpdateDim.Text = “Update Dimensions”) Then

btnAdd.Enabled = False
txtUnique.Enabled = False
cbTypeUnique.Enabled = False
txtPK.Enabled = False
txtValUnique.Enabled = False

If (cbTableName.SelectedIndex = -1) Then
MessageBox.Show(“Please select a Table Name to update”, “Information”, MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
cmd.Connection = New System.Data.SqlClient.SqlConnection(ConnectionString)
sqlupdatetable = “Select syscolumns.name, systypes.name, syscolumns.length from syscolumns, SysObjects, systypes where((Sysobjects.name = ‘” & cbTableName.SelectedItem.ToString & “‘) and (Sysobjects.xtype = ‘U’) and (sysobjects.xtype not like ‘PK’) and (Sysobjects.id = syscolumns.id) and (systypes.xtype = syscolumns.xtype)) order by syscolumns.colorder”

cmd = New System.Data.SqlClient.SqlCommand(sqlupdatetable, cmd.Connection)

objreader = cmd.ExecuteReader

While objreader.Read
counter += 1
If (counter = 1) Then
txtPK.Text = objreader(0)
End If
If (counter = 2) Then
txtUnique.Text = objreader(0)
cbTypeUnique.SelectedItem = objreader(1)
txtValUnique.Text = objreader(2).ToString
End If
If (counter > 2) Then
lbFields.Items.Add(objreader(0) + ” ” + objreader(1) + ” (” + objreader(2).ToString + “)”)
End If
End While


btnUpdateDim.Text = “Save Dimensions”
ElseIf (btnUpdateDim.Text = “Save Dimensions”) Then
btnAdd.Enabled = True
btnUpdateDim.Text = “Update Dimensions”
End If
Catch ex As Exception
End Try
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: