Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

asp :: list database tables

asp :: list database tables

<%@ Page Language="VB" %>
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cnnTables As New System.Data.SqlClient.SqlConnection
        cnnTables.ConnectionString = "Data Source=localhost;Initial Catalog=DB_NAME;User ID=USER;Password=PASS;"

        cnnTables.Open()

        gridTables.DataSource = cnnTables.GetSchema("Tables")
        gridTables.DataBind()

        cnnTables.Close()
    End Sub

</script>
<html>
<head>
    <title>List Tables In Database</title>
</head>
<body>
<form id="myForm" runat="server">

<asp:GridView ID="gridTables" runat="server" />

</form>
</body>
</html> 

Case sensitivity in PostgreSQL

When I started using PostgreSQL, it seemed odd that when I created a table called Users with column names like userId, userPassword, etc. When I would select these items from the table, the column and table names would all be in lowercase. It's quite simple really, I wasn't using quotes :) Below is an example of how to maintain your case in PostgreSQL:

This will all come out lowercase
create table Users (
  userId integer unique not null,
  userFirstName varchar(50) not null,
  userLastName varchar(50) not null
);


Whereas this will come out as you expect it to
create table "Users" (
  "userId" integer unique not null,
  "userFirstName" varchar(50) not null,
  "userLastName" varchar(50) not null
);

Scripting schema updates in MSSQL #1

This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.

From: http://haacked.com/

IF NOT EXISTS
(
    SELECT * FROM [information_schema].[columns]
    WHERE    table_name   = 'Customer'
    AND      table_schema = 'dbo'
    AND      column_name  = 'FavoriteColorId'
)
BEGIN
    ALTER TABLE [dbo].[Customer]
    ADD FavoriteColorId int

Create a PivotTable cache and report from ADODB.Recordset

// description of your code here
Create a PivotTable cache and report from ADODB.Recordset

Dim objPivotCache   As Object
Set objPivotCache = ActiveWorkbook.PivotCaches.Add( _
    SourceType:=xlExternal)
Set objPivotCache.Recordset = rsNostro
With objPivotCache
    .CreatePivotTable TableDestination:=Range("A43"), _
        TableName:="Performance"
End With

With ActiveSheet.PivotTables("Performance")
    .SmallGrid = False
    With .PivotFields("C_4")
        .Orientation = xlRowField
        .Position = 1
    End With
    With .PivotFields("C_2")
        .Orientation = xlColumnField
        .Position = 1
    End With
    With .PivotFields("C_7")
        .Orientation = xlDataField
        .Position = 1
    End With
End With