**STORED PROCEDURE**
Alter procedure dbo.BooksUpdate
@BookName nvarchar(10),
@BookReview nvarchar(50),
@BookID bigint --- Delete the Output
As
---Set @BookID = 0 - Delete this line
-- update books table
Update Books
Set Books.BookName = @BookName,
Books.BookName = @BookReview,
Where Books.BookID = @BookID
---Set @BookID = @@Identity - Delete this line // @@identity returns the last generated identity - you have to use @@rowcount instead. Anyways you dont need it.
---If @BookID Is Null Set @BookID = 0 // Dont need this line
Return
GO
***Call to the Database/Stored Procedure*** (bus obj)
public class Books
{
private static string connBookUpdate = "Data Source=server1;Integrated Security=True;Initial Catalog=BookListings";
private static long bookID = 0;
public static long UpdateBooks(string bookName, string bookReview, long bookId)
{
SqlParameter cmdParm;
using (SqlConnection connection = new SqlConnection(connBookUpdate))
{
using (SqlCommand command = new SqlCommand("BooksUpdate", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@BookName", SqlDbType.Varchar, 100));
command.Parameters.Add(new SqlParameter("@BookReview",SqlDbType.Varchar, 100));
command.Parameters.Add(new SqlParameter("@BooId",SqlDbType.BigInt));
connection.Open();
return Convert.ToLong(command.ExecuteNonQuery()); // This returns number of rows updated.
//bookID = (long)command.Parameters["@BookID"].Value; -- Delete this line
}
Let me know if you need any further help. My idea was to explain the problem not to post correct code.