hi I need help with an odd problem I'm experiencing with my update. I have an update stored procedure in SQL and I want to use that update in c# form , iv don that yet my problem is that my update does not work on my form, it says that records have been updated yet when I check on SQL nothing has been updated. my update stored procedure works perfectly when I execute it, so I'm not sure where the problem lies. below I will post both my update c# code and stored procedure script.
thanks in advance
private void DoUpdate()
{
try
{
string picLoc = "C:\\Users\\Dee\\Pictures\\PIC\\download.jpg";
try
{
byte[] img = null;
FileStream fs = new FileStream(picLoc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string connectionString = "Data Source=(local);Initial Catalog=MediaPlayer;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.updateBooks", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value = NametextBox.Text.ToString();
cmd.Parameters.AddWithValue("@FileName", SqlDbType.NVarChar).Value = FileNametextBox.Text.ToString();
cmd.Parameters.AddWithValue("@FileSize", SqlDbType.Float).Value = Convert.ToDouble(fileSizetextBox.Text);
cmd.Parameters.AddWithValue("@FilePath", SqlDbType.NVarChar).Value = FilePathtextBox.Text.ToString();
cmd.Parameters.AddWithValue("@DateAdded", SqlDbType.Date).Value = DateAddeddateTimePicker.Text.ToString();
cmd.Parameters.AddWithValue("@MediaLength", SqlDbType.NVarChar).Value = MediaLengthtetextBox.Text.ToString();
cmd.Parameters.AddWithValue("@MediaSubType", SqlDbType.NVarChar).Value = MediaSubtypetextBox.Text.ToString();
cmd.Parameters.AddWithValue("@MediaType", SqlDbType.NVarChar).Value = MediaTypetextBox.Text.ToString();
cmd.Parameters.Add(new SqlParameter("@Thumbnail", img));
cmd.Parameters.AddWithValue("@DateAquired", SqlDbType.DateTime).Value = DateAquiredDatetimepicker.Text.ToString();
cmd.Parameters.AddWithValue("@Author", SqlDbType.NVarChar).Value = AuthortextBox.Text.ToString();
cmd.Parameters.AddWithValue("@Publisher", SqlDbType.NVarChar).Value = PublishertextBox.Text.ToString();
cmd.Parameters.AddWithValue("@BooksName", SqlDbType.NVarChar).Value = BooksNametextBox.Text.ToString();
cmd.Parameters.AddWithValue("@SeriesTitle", SqlDbType.Date).Value = SeriesTitletextBox.Text.ToString();
cmd.Parameters.AddWithValue("@SeriesNumber", SqlDbType.NVarChar).Value = SeriesNumberTextBox.Text.ToString();
cmd.Parameters.AddWithValue("@Genre", SqlDbType.NVarChar).Value = genretextBox.Text.ToString();
cmd.Parameters.AddWithValue("@Synoposis", SqlDbType.NVarChar).Value = SynoposistextBox.Text.ToString();
cmd.Parameters.AddWithValue("@YearOfPublication", SqlDbType.NVarChar).Value = YearOfPublicationdatetimepicker.Text.ToString();
cmd.Parameters.AddWithValue("@ISBN ", SqlDbType.NVarChar).Value = ISBNtextBox.Text.ToString();
cmd.Parameters.Add(new SqlParameter("@BookCover", img));
SqlParameter parm1 = new SqlParameter("@GeneralID", SqlDbType.Int);
parm1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm1);
SqlParameter parm = new SqlParameter("@BookID", SqlDbType.Int);
parm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm);
MessageBox.Show(cmd.ExecuteNonQuery().ToString() + " record(s) Updated.");
conn.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("error is " + ex.Message);
}
}
finally
{ }
}
SQL SCript
USE [MediaPlayer]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[updateBooks]
@Name nvarchar (50),
@FileName nvarchar(50),
@FilePath nvarchar(50),
@FileSize float,
@DateAdded date,
@MediaLength nvarchar (50),
@MediaSubType nvarchar (50),
@MediaType nvarchar (50),
@Thumbnail image,
@DateAquired datetime,
@BooksName nvarchar (50),
@Publisher nvarchar(50),
@Author nvarchar(50),
@YearOfPublication date,
@Genre nvarchar (50),
@ISBN nvarchar (50),
@Synoposis nvarchar(max),
@SeriesTitle nvarchar(50),
@SeriesNumber nvarchar (50),
@BookCover image,
@GeneralID int output,
@BookID int output
AS
BEGIN
update dbo.Book
SET
BooksName=@BooksName,
Publisher=@Publisher,
Author =@Author,
[Year of publication] =@YearOfPublication,
Genre =@Genre,
ISBN=@ISBN,
Synoposis=@Synoposis,
[Series Title]= @SeriesTitle,
[Series Number] =@SeriesNumber,
[Book Cover] =@BookCover
from Book
Where BookID = @BookID
select @@ROWCOUNT
update dbo.General
SET
Name =@Name,
FileName= @FileName,
FilePath= @FilePath,
FileSize=@FileSize,
DateAdded= @DateAdded,
MediaLength =@MediaLength,
MediaSubType = @MediaSubType,
MediaType = @MediaType,
Thumbnail =@Thumbnail,
DateAquired= @DateAquired
where GeneralID = @GeneralID
END