Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Need help with stored procedureNeed help with stored procedure
Previous
 
Next
New Post
5/11/2010 8:15 PM
 

I am building a website for our fishing club and developing a module for allow users to register their fish. I need help with a stored procedure that will return the fish a individual angler registered that day. Here is what I have so far:

create procedure YourCompanys_GetRegisteredFishToday
 @ModuleId int
as

select ModuleId,
  ItemId,
  Species,
  FishLength,
  Points,
  CreatedByUser,
  YourCompanys_FishScores.CreatedDate,
  'CreatedByUserName' = Users.FirstName + ' ' + Users.LastName
from YourCompanys_FishScores
inner join Users on YourCompanys_FishScores.CreatedByUser = User.UserId
where ModuleId = @ModuleId
 and YourCompanys_FishScores.CreatedDate >= DATEADD(day,DATEDIFF(day,0,GETDATE()),0) AND
  YourCompanys_FishScores.CreatedDate < DATEADD(day,DATEDIFF(day,0,GETDATE()),1)
GO

The problem is I keep getting this error:
System.Data.SqlClient.SqlException: Cannot call methods on nvarchar. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at DotNetNuke.Data.SqlDataProvider.ExecuteADOScript(String SQL) at DotNetNuke.Data.SqlDataProvider.ExecuteScript(String Script, Boolean UseTransactions) create procedure YourCompanys_GetRegisteredFishToday @ModuleId int as select ModuleId, ItemId, Species, FishLength, Points, CreatedByUser, YourCompanys_FishScores.CreatedDate, 'CreatedByUserName' = Users.FirstName + ' ' + Users.LastName from YourCompanys_FishScores inner join Users on YourCompanys_FishScores.CreatedByUser = User.UserId where ModuleId = @ModuleId and YourCompanys_FishScores.CreatedDate >= DATEADD(day,DATEDIFF(day,0,GETDATE()),0) AND YourCompanys_FishScores.CreatedDate < DATEADD(day,DATEDIFF(day,0,GETDATE()),1)

  

 
New Post
5/12/2010 3:55 AM
 
  1. Can you please post the table definition, there might be a problem with data types.
  2. Instead of
    'CreatedByUserName' = Users.FirstName + ' ' + Users.LastName
    use
    Users.FirstName + ' ' + Users.LastName CreatedbyUserName
    or, even better:
    Users.DisplayName CreatedByUserName
  3. if you need the result for a single user only, pass the user ID as well as a parameter and return only the sigle record.

 


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
5/12/2010 9:00 AM
 
Thanks for the response Sebastian.
Here is my table definition:
    [ModuleID] [int] NOT NULL,
    [ItemID] [int] NOT NULL IDENTITY(1, 1),
    [Species] [nvarchar] (10) NOT NULL,
    [FishLength] [float] NOT NULL,
    [Points] [int] NOT NULL,
    [CreatedByUser] [int] NOT NULL,
    [CreatedDate] [datetime] NOT NULL

What I am trying to accomplish is that when the User registers a fish it populates a gridview so they can see all of the entries they made that day. It also will give them the opportunity to delete any mistakes they may have made. So if the user registers 3 fish the gridview will list all 3 of their enties but nobody elses.
Hope this makes sense.
 
New Post
5/12/2010 9:46 AM
 
- did you check out #2 from my suggestions? - according to your reply, you should also consider the change mentioned in #3 (or addditionally, if there is a list of all fishes per day as well)

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
5/12/2010 12:27 PM
 
OK I implemented both of your suggestions and it is working very well! Thanks,
 
Previous
 
Next
HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Need help with stored procedureNeed help with stored procedure


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out