Interesting problem with getting OUTPUT parameters from SQL Server using C#

 I have the following SP:

 

Create procedure dbo.example

(

@test INT OUTPUT

)

AS

BEGIN

SET @test = 5

SELECT * from Users

END

GO

 

 

and when I try calling it from C# using an SqlCommand with adding an output parameter and getting it's value, I get that the value is NULL. (I should mention that I use ExecuteReader)

However,  if I alter the SP and remove the select line, the c# code works and returns the value 5.

 

Read More

How to keep RETURNURL when accessing a secure page, yet disable it when logging in explicitly ?

I have a loginstatus control on my masterpage so that a user would have the ability to login no matter what page of the website he is on.  When he clicks on that, it brings him to the login page with the login control.  I explicitly hardcoded a specific page for the destinationpageurl attribute of the login control, but it seems the returnurl overrides that setting.  It seems the returnurl is set for the page I was previously on.  Why is the returnurl being set if I wanted to just login explicitly?  How would the hardcoded destinationpageurl ever get a chance to work then?

However, the returnurl is very useful to me in other situations.  For example, say an unauthenticated user is browsing the site and he clicks on a button (or link or whatever) that leads to a secure page (all of my secure pages are under a folder allowing only authenticated users to view them).  The site directs him automatically to the login page with the returnurl instructing the site to forward him to the intended destination after successful login.  This is desirable.  However, as stated earlier, when a user explicitly clicks on the loginstatus to log in, I want him to be directly led to a specfic page (like myaccount.aspx or something).

How do I do this?

Thanks in advance.

Read More

How to remove a star from Rating control?

I'm trying to let the user set their preference on a scale of 0 to 5.  Something like:

Pref 1  ***** select rating

Pref 2 ***** select rating

Pref 3 ***** select rating

 After they make a selection I want to remove a star from the other unselected rating controls.  So in other words the rating values can only be used once.  How can I accomplish this?

 

Read More

new to deploying

I created a simple web page to load onto a remote site using Visual Web Developer Express 2005. All it contained was the word "Hello". I hit Build Website and then I used the aspnet_compiler and then ftp to transfer the compiled files to the remote server. When I tried to access the page, all it showed was:

"This is a marker file generated by the precompilation tool, and should not be deleted!"

What am I doing wrong?

Read More

Very Strange Data Conversion (?) Error

 Using SQL Server 2005, I hve encountered a very strange error which I cannot figure out.  The simplified stored proc below basically does a select and sorts the records based on the column name given in the @SortCol parameter.  When I enter the field names bapk, jhpk, etc everything works fine.  The records are returned sorted by the field name entered into the parameter.  The first eight variables are  field names and types

 When I enter the field name 'descr' into the @SortCol variable/parameter, I receive the error:

 Msg 295, Level 16, State 3, Procedure CMSCheck2, Line 28
Conversion failed when converting character string to smalldatetime data type.

I don't see where this is coming from at all.  The problem is in the  stored proc lines beginning with 'CASE @SortCol'

If I take out the lines and just use  OVER (Order By descr) as RowNum   — everything is fine

If I delete the line  WHEN 'descr' THEN descr  — everything is fine, it just falls through to the default.

 What is the problem?  Where is a conversion to smalldatetime coming from?   I've been working on this one for a while, and cannot figure it out.  It must be something simple.

 Thanks,

Mike Thomas
 

Below is the stored proc and a testing script

 

TESTING SCRIPT

USE biz03
GO

DECLARE
  @bapk int,
  @jhpk int,
  @transdate smalldatetime,
  @number smallint,
  @descr nvarchar(50),
  @debit decimal(9,2),
  @credit decimal(9,2),
  @cmonth tinyint,
  @StartRowIndex int,
  @MaxRows int,
  @AlphaChar varchar(1),
  @SortCol varchar(20)

SET @MaxRows = 10
SET @StartRowIndex = 0
SET @SortCol = 'descr'
SET @AlphaChar = ''

EXEC [dbo].[CMSCheck2]
  @bapk,
  @jhpk,
  @transdate,
  @number,
  @descr,
  @debit,
  @credit,
  @cmonth,
  @StartRowIndex,
  @MaxRows,
  @AlphaChar,
  @SortCol

 

STORED PROC 

 

 ALTER PROCEDURE [dbo].[CMSCheck2]
  @bapk int,
  @jhpk int,
  @transdate smalldatetime,
  @number smallint,
  @descr nvarchar(50),
  @debit decimal(9,2),
  @credit decimal(9,2),
  @cmonth tinyint,
  @StartRowIndex int,
  @MaxRows int,
  @AlphaChar varchar(1) = null,
  @SortCol varchar(20) = null

AS
BEGIN

SET NOCOUNT ON

DECLARE @lPaging bit
IF @AlphaChar is null
  SET @lPaging = 0
ELSE
  SET @lPaging = 1;

WITH BankListTemp AS
  (SELECT   bapk, jhpk, transdate, number,
    descr, debit, credit, cmonth, ROW_NUMBER()
    OVER (ORDER BY
    CASE @SortCol
       WHEN 'bapk' THEN bapk
       WHEN 'jhpk' THEN jhpk
       WHEN 'transdate' THEN transdate
       WHEN 'number' THEN number
       WHEN 'descr' THEN descr  — problem here   —
       WHEN 'debit' THEN debit
       WHEN 'credit' THEN credit
       WHEN 'cmonth' THEN cmonth
       ELSE bapk
    END) as RowNum
  FROM bank)

SELECT TOP (@MaxRows)    bapk, jhpk, transdate, number,
    descr, debit, credit, cmonth, Rownum
FROM
 ( SELECT BankListTemp.*,
    (SELECT COUNT(*) FROM BankListTemp) AS RecCount
      FROM BankListtemp) Bank

END

 

Read More

Interfaces

I have recently fallen in love with interfaces – they make it so easy to distribute uniform changes across many objects… that is, until you want to add a member who's signature changes depending on which class inherits it

For example, I have two classes, Customers, and Events.  Both inherit my "CustomCollection" interface.  I want the interface to force the implementation of an Add method, but inevitably their arguments are different:  Add(Customer cust) , Add(Event ev). Is there a way to tell the interface that the parameters can change depending on the class?

 

 

 

Read More

RegisterClientScriptInclude in masterpage

Hi,

I’m trying to include and use a javascript file in my masterpage… niftycube actually. Anyways, trying to add this javascript and call the function is proving to be quite difficult. I’ve looked over most of the solutions on this forum already, but none seem to work for me. Here’s what I have so far on the Page_Load.

String csname = "niftycube";
ClientScriptManager cs = Page.ClientScript;
String csurl = "niftycube.js";
Type cstype = this.GetType();

// Check to see if the include script exists already.
if (!cs.IsClientScriptIncludeRegistered(cstype, csname))
{
     cs.RegisterClientScriptInclude(cstype, csname, ResolveUrl(csurl));
}

So I’ve actually tried a variety of different ways to get the javascript file properly included. I’ve used different values for ‘csurl’ include “~/niftycube.js”, “niftcube.js”, “~/scripts/niftycube.js” (after moving it there of course), and so on. No matter what I do, I’m getting a Javascript error saying “Syntax error, Line 4, Char 1”.

When I look at the source code actually generated, it actually APPEARS to be correct! But I’m still getting the syntax error warning. As soon as I removed the “RegisterClientScriptInclude” line of code, the syntax error warning goes away, not to mention the calls to the javascript functions by adding RegisterClientScriptBlock are also failing.

<script src="/CentralProject/niftycube.js" type="text/javascript"></script>