Hi all,
I'm having a litle issue, I've already looked at some examples, but my problem persits. I'm trying to call a insert stored procedure in my C# windows application. but i receive an error message telling me that i'm not passing the parameter.
try
{
using (SqlConnection cnn = new SqlConnection(cnnStr.Text))
{
using (SqlCommand cmd = new SqlCommand("[Files_Insert]", cnn))
{
FileStream fs = File.Open(tbFile.Text, FileMode.Open, FileAccess.Read);
int length = (int)fs.Length + 1;
fs.Close();
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm = new SqlParameter("@P_FILE_ID", SqlDbType.UniqueIdentifier, 32);
prm.Direction = ParameterDirection.ReturnValue;
prm.SqlValue = null;
cmd.Parameters.Add(prm);
prm = new SqlParameter("@P_FILE", SqlDbType.VarBinary, length);
prm.SqlValue = File.ReadAllBytes(tbFile.Text);
cmd.Parameters.Add(prm);
cnn.Open();
int i = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
and for inserting data into the sql table, i use this stored procedure;
ALTER PROCEDURE [dbo].[Files_Insert](
@P_FILE_ID uniqueidentifier output,
@P_FILE varbinary(MAX)
)
AS
BEGIN
DECLARE @GUID uniqueidentifier
SET @GUID = NEWID()
SET NOCOUNT ON;
INSERT INTO [FILE_VALUE]
(
FILE_ID,
[FILE]
)
VALUES
(
@GUID,
@P_FILE
)
SET @P_FILE_ID = @GUID
END
And the eror message i'm receiving is this one
I'm having a litle issue, I've already looked at some examples, but my problem persits. I'm trying to call a insert stored procedure in my C# windows application. but i receive an error message telling me that i'm not passing the parameter.
try
{
using (SqlConnection cnn = new SqlConnection(cnnStr.Text))
{
using (SqlCommand cmd = new SqlCommand("[Files_Insert]", cnn))
{
FileStream fs = File.Open(tbFile.Text, FileMode.Open, FileAccess.Read);
int length = (int)fs.Length + 1;
fs.Close();
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm = new SqlParameter("@P_FILE_ID", SqlDbType.UniqueIdentifier, 32);
prm.Direction = ParameterDirection.ReturnValue;
prm.SqlValue = null;
cmd.Parameters.Add(prm);
prm = new SqlParameter("@P_FILE", SqlDbType.VarBinary, length);
prm.SqlValue = File.ReadAllBytes(tbFile.Text);
cmd.Parameters.Add(prm);
cnn.Open();
int i = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
and for inserting data into the sql table, i use this stored procedure;
ALTER PROCEDURE [dbo].[Files_Insert](
@P_FILE_ID uniqueidentifier output,
@P_FILE varbinary(MAX)
)
AS
BEGIN
DECLARE @GUID uniqueidentifier
SET @GUID = NEWID()
SET NOCOUNT ON;
INSERT INTO [FILE_VALUE]
(
FILE_ID,
[FILE]
)
VALUES
(
@GUID,
@P_FILE
)
SET @P_FILE_ID = @GUID
END
And the eror message i'm receiving is this one