Saturday, March 31, 2012

Simpel Database Question.............

I use the Personal Starter Kit.

What I like to do:

If somebody add a new PhotoAlbum, then I like to store the UserName also in the Table >Albums<.


What I already did:

I add a new field to the Album Table:

>Owner = nvarchar(50) (can be zero)

I changed personal-add.sql like this (bold section):

CREATE PROCEDURE AddAlbum
@dotnet.itags.org.Caption nvarchar(50),
@dotnet.itags.org.IsPublic bit,
@dotnet.itags.org.Owner nvarchar(50)
AS
INSERT INTO [Albums] ([Caption],[IsPublic],[Owner]) VALUES (@dotnet.itags.org.Caption, @dotnet.itags.org.IsPublic, @dotnet.itags.org.Owner)
RETURN
GO

I changed PhotoManager.vb like this (:

Imports System.Web.UI.WebControls.WebParts.UserPersonalizationStateInfo

and at the code (bold section):

Public Shared Sub AddAlbum(ByVal Caption As String,ByVal Owner As String, ByVal IsPublic As Boolean)
Dim instance As UserPersonalizationStateInfo
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Personal").ConnectionString)
Using command As New SqlCommand("AddAlbum", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@dotnet.itags.org.Caption", Caption))
command.Parameters.Add(New SqlParameter("@dotnet.itags.org.Owner", instance.Username))
command.Parameters.Add(New SqlParameter("@dotnet.itags.org.IsPublic", IsPublic))
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub

But I get this Error:

ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'AddAlbum' that has parameters: Caption, IsPublic.

What I am missing??

Thanks for every answer!

Regards Mikel

Isn't "Owner" an SQL keyword?

Thanks Steve, but this didnt solve it.

I renamed Owner as MyOwner (also changed the Tablefieldname).

Same Error.

Regards Mikel


The error is not becoz of the fields in the stored procedures (but its always good to have variable names other than keywords). Since you have customized the AddAlbum field by adding another parameter, one of the ObjectDataSource is still referencing the old method with 2 parameters(Caption, IsPublic). Click on the small arrow on top of the ObjectDataSource, -> Configure Data Source and in the Insert Tab, select the method again ( with 3 parameters). Refresh the methods

Thanks


Thanks for Your aswer!

I did the Update of the ObjectDataSource.

Then I got an error because off:

command.Parameters.Add(New SqlParameter("@.Owner", instance.Username))

He said that there is no object for it.

I changed this line to:

command.Parameters.Add(New SqlParameter("@.MyOwner", HttpContext.Current.User.Identity.Name))

and I get this error:


Exception Details:System.Data.SqlClient.SqlException: For the procedure or funktion Album are too much arguments declared.

Source Error:

Line 164: command.Parameters.Add(New SqlParameter("@.MyOwner", HttpContext.Current.User.Identity.Name))
Line 165: connection.Open()
Line 166: command.ExecuteNonQuery()
Line 167: End Using
Line 168: End Using


Source File:C:\Downloads\ASPNET\App_Code\PhotoManager.vb Line:166

Regards Mikel


Problem solved, works fineYes!

I needed to update the stored procedure for Add Album, what we find under Datas and Folder stored procedure.

Regards Mikel

0 comments:

Post a Comment