Archive for May, 2006

Create Stored Procedure

‘We wanna catch errors
Try
    ‘Defining the server and database we wan’t to use
    Dim connect_string As String = “server=” & server_ip & “;uid=” & user_id & “;pwd=” & password & “;database=” & database
    ‘Creating a SQL-connection to the server
    Dim db_connection As New SqlConnection(connect_string)
    ‘Creating a SQL-command
    Dim sql_command As New SqlCommand
    ‘Adding the SQL-connection to the SQL-command
    sql_command.Connection = db_connection

    ‘Adding commandtext to the SQL-command
    sql_command.CommandText = _
“CREATE PROCEDURE dbo.spInsertImages ” & _
” @imageName VARCHAR(150),” & _
” @imageAttr int,” & _
” @imageLastAccessTime datetime,” & _
” @imageLastWriteTime datetime,” & _
” @imageExtension varchar(5),” & _
” @imageCreationTime datetime,” & _
” @imageDirectory varchar(500),” & _
” @imageFullName varchar(650),” & _
” @imageLength int ” & _
” AS ” & _
“INSERT INTO tblImages ” & _
       “(imageName, imageAttr, imageLastAccessTime, imageLastWriteTime, ” & _
       “imageExtension, imageCreationTime, imageDirectory, ” & _
       “imageFullName, imageLength) VALUES (” & _
       “@imagename,  ” & _
       “@imageAttr, ” & _
       “@imageLastAccessTime,  ” & _
       “@imageLastWriteTime,  ” & _
       “@imageExtension, ” & _
       “@imageCreationTime,  ” & _
       “@imageDirectory,  ” & _
       “@imageFullName,  ” & _
       “@imageLength) ”

    ‘Opening the connection to the database
    db_connection.Open()
    ‘Executing the SQL-command
    sql_command.ExecuteNonQuery()
    ‘Closing the connection to the database
    db_connection.Close()

    ‘Cleaning up
    db_connection = Nothing
    connect_string = Nothing
    sql_command = Nothing

    ‘Returning true to the caller if successfull
    Return True

Catch ex As Exception

    ‘Throwing the exception to the caller if something went wrong
    Throw ex

End Try

Comments

Execute and retrieve from Stored Procedure

Dim sConnectionString As String = “server=server_ip_here;uid=sa;pwd=type_password_here;database=Northwind”
Dim cnNorthwind As New SqlConnection(sConnectionString)

Dim cmdOrders As New SqlCommand(“CustOrderHist”, cnNorthwind)
cmdOrders.CommandType = CommandType.StoredProcedure

‘Set up parameter for stored procedure

Dim prmCustomerID As New SqlParameter
prmCustomerID.ParameterName = “@CustomerID”
‘prmCustomerID.SqlDbType = SqlDbType.VarChar
‘prmCustomerID.Size = 5
prmCustomerID.Value = “ALFKI”

‘Adding the parameters to my sql-command
cmdOrders.Parameters.Add(prmCustomerID)
Dim daGetOrders As New SqlDataAdapter(cmdOrders)

‘Creating a dataset
Dim dsOrders As New DataSet

‘Filling the dataset
daGetOrders.Fill(dsOrders, “Orders”)

‘Showing the content of the stored procedure
DataGrid1.DataSource = dsOrders.Tables(“Orders”)

Comments

Programming with Visual Basic .NET

During both working hours and in my free-time I do a little Visual Basic/Visual Basic
.NET programming.

I’m currently working on:
– a direct ftp edit program (ftp editor) – a program that enables you to edit text-files
(html, asp, php, aspx etc.) directly on the FTP-server.

– a program which gets and updates your favorites – that is, gets the Favicons and
checks if the URL exists (BETA released friday, july 22, 2005)

– an example-program for different language interfaces

– a program for controlling a DEKO-application (text-generator for news)

– a program for extracting subtitles from iNEWS (TV-production
system)

I thougt, that I might as well publish some of these programs here.

Comments

Error configuring WebSite (ASP.NET | Visual Studio)

Having problem with “Error configuring WebSite” and a message tellingyou, that you’ll need to do it manually when creating a new website???- then you’ll have to:

1) Choose “Start > Programs > Microsoft Visual Studio 2005 > VisualStudio Tools >
Visual Studio 2005 Command Prompt”

2) Enter ‘aspnet_regiis -i -enable’ – and hit Enter.

Comments

« Previous Page « Previous Page Next entries »