Calling SQL Stored procedure from codebehind problems

Posted on 2012-04-07
Last Modified: 2012-05-12
hello, I am having a bit problems with this one and I dont know why, it should work.

The stored procedure works fine when I execute, but when I use codebehind to call it, thats where it does not work.

codebehind (vb .net)
Function ssRadioStatistik(ByVal ChannelName As String, ByVal AlbumTitle As String, ByVal TrackTitle As String, ByVal DisplayArtist As String, ByVal StartTime As String)
            If DisplayArtist.ToLower.Contains("wrd1") = True And DisplayArtist.ToLower.Contains("wrd2") = True Then

'tested with a msgbox to see if it comes to here and it does...

                Dim myConnectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString


                Dim myConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(myConnectionString)
                    Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand("ErDetsStoredProcedure", myConnection)
                    command.CommandType = CommandType.StoredProcedure
                    command.Parameters.AddWithValue("@ChannelName", ChannelName)
                    command.Parameters.AddWithValue("@AlbumTitle", AlbumTitle)
                    command.Parameters.AddWithValue("@TrackTitle", TrackTitle)
                    command.Parameters.AddWithValue("@DisplayArtist", DisplayArtist)
                    command.Parameters.AddWithValue("@StartTime", StartTime)
                End Try

            End If
        Catch ex As Exception
        End Try
    End Function

Open in new window

Stored procedure code(works fine when executed)
ALTER PROCEDURE [Joachim_ErDets].[ErDetBieberStoredProcedure]
	@ChannelName nvarchar(50),
    @AlbumTitle nvarchar(50),
	@TrackTitle nvarchar(50),
	@DisplayArtist nvarchar(50),
	@StartTime datetime

IF NOT EXISTS (SELECT * FROM ErDetsTable WHERE StartTime = @StartTime AND ChannelName = @ChannelName)
    INSERT INTO ErDetsTable (ChannelName, AlbumTitle, TrackTitle, DisplayArtist, StartTime, DatetimeStamp)
    VALUES (@ChannelName, @AlbumTitle, @TrackTitle, @DisplayArtist, @StartTime, GETDATE())

Open in new window

it gives no error when I try the use the codebehind to execute it, but it does not write anything in table. (tested the stored procedure by executing it, works great)

Thanks in advance, I have no clue why this does not work.
Question by:JoachimPetersen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 36

Accepted Solution

Miguel Oz earned 250 total points
ID: 37818599
You need to pass StartTime as date time parameter.
Replace line 20:
command.Parameters.AddWithValue("@StartTime", StartTime)
'Add the parameter.
Dim parameter As SqlParameter= command.Parameters.Add("@dt",  System.Data.SqlDbType.DateTime);
'Set the value.
parameter.Value = DateTime.Now;
' Execute the proc

LVL 83

Expert Comment

ID: 37819699
>thats where it does not work.

LVL 14

Expert Comment

ID: 37822414
you are missing


Open in new window

again if u face issues, add

 Catch ex As Exception
response.write ex.toString()  'For Testing only
        End Try

Open in new window

LVL 36

Expert Comment

by:Miguel Oz
ID: 37825745
I already mentioned command.ExecuteNonQuery() as part of my previous post.
LVL 14

Expert Comment

ID: 37826334

Sorry about that..... truly, i didn't read your comment properly..

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question