Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Record Lock
Message
De
04/03/2003 10:02:58
 
 
À
04/03/2003 09:00:49
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
00760359
Message ID:
00760872
Vues:
17
>How do you put the value in the dataset? The key is updating, but I keep getting a null reference error for my dataset. Here is my process so far:
>

Change your stored procedure to return the key as an output parameter
'Stored Procedure
CREATE PROCEDURE spGetKey
@TableName varchar(40)
,@KeyField int OUTPUT
AS
UPDATE tblESCGlob
SET
intKeyValue = intKeyValue + intIncrementValue
FROM
tblESCGlob
WHERE
strTableName = @TableName
GO
>'Here is my code
>strSQL = "spGetKey"
>objConn = ""
>dim objCmd As SqlClient.SqlCommand
>objCmd = New SqlClient.SqlCommand(strSQL, objConn)
> lADO.objCmd.CommandType = CommandType.StoredProcedure
>
>Dim TableName As SqlClient.SqlParameter = _
> lADO.objCmd.Parameters.Add("@TableName", SqlDbType.VarChar)

Add the output parameter to the collection to. I am not sure of the exact syntax, perhaps Cathi or Bonnie could help you with that.

Also, I don't see code where you are populating the parameter with the table name. Or is that what you are doing in the fill?

>TableName.Value = lcTableName
>
>objDS = New DataSet()
>objConn.Open()
>objDA = New SqlClient.SqlDataAdapter(Me.objCmd)
>objDA.Fill(objDS, "PrimaryKey")

Once again, once you run the code here an call the SP... the OutPUT parameter should have the value you are looking for... you can use that to insert into your data set.

>objConn.Close()
>
>Thanks for the help.

You should probably encapsulate all this into a method in your data layer somewhere as a GetNextKey() method which accepts the table name and returns the key as an integer.

BOb
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform