Hi,
I'm using VB .NET and SQL Server 2000.
I'm using the SqlDataAdapter control with the Stored Procedures
generated by its Wizard to Select, Insert, Delete and Update rows in
the database tables.
an output parameter to the client VB application and also to manage
transactions.
Now what I wonder is how can I in a smart way handle the errors and
generate user friendly error messages in the VB client application
since I couldn't succeed generating any messages in the stored
procedure with Raiserror/Print.
Would appreciate an example code regarding the code below.
I also wonder what IS the returned value in intRetVal. Is it the
number of rows effected?
Thanks for any help in advance
Ali Eghtebas, Sweden
******************* In SQL Server 2000 ********************
CREATE PROCEDURE dbo.usp_Ins_ArtikelKat
(
)
AS
SET NOCOUNT OFF;
Begin Tran -- Start a transaction
--SELECT tintCategory_ID, strCategory FROM tbl_ProdCat WHERE
-- If an Error has occurred
Begin
-- Could I show an error msg here? Raiserror or Print did't work
Rollback Tran -- Cancel the transaction
End
Else
-- If there is no errors
Begin
Commit Tran -- Commit the transaction
End
-- Moving the Select statement down here makes the datarow in the
dataset to
-- have null as the key value if the transaction is rolled back. That
makes it
-- easy to find the rows in the dataset that could not be updated in
the
-- database table.
SELECT tintCategory_ID, strCategory FROM tbl_ProdCat
parameter
GO
*******************************************************
********* In my VB client application *********
'Adds an Product Category to the DB(tbl_ProdCat)
Private Sub btnArt_AddCat_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnArt_AddKat.Click
Dim dsProdCat As New DataSet()
Dim drNewProdCat As DataRow
Dim intRetVal%,intError%
SqlDataAdapter1.Fill(dsProdCat, "tbl_ProdCat")
drNewProdCat = dsProdCat.Tables("tbl_ProdCat").NewRow
drNewProdCat.Item("strCategory") = txtCategory.Text
dsProdCat.Tables("tbl_ProdCat").Rows.Add(drNewProdCat)
intRetVal = SqlDataAdapter1.Update(dsProdCat.Tables("tbl_ProdCat"))
End Sub
***********************************************