ALTER PROCEDURE [dbo].[UploadFile] (
@FileName VARCHAR(150),
@FileSize INT,
@FileContentType VARCHAR(200),
@FileExtension VARCHAR(10),
@FileContent VARCHAR(MAX)
)
AS
BEGIN
INSERT INTO FilesData( FileName,FileSize,FileContentType,FileExtension,FileContent ) VALUES
( @FileName,@FileSize,@FileContentType,@FileExtension,@FileContent )
END
这个SaveFile.cs
public class SaveFile
{
public string FileName { set; get; }
public string FileExtension { set; get; }
public byte[] FileContent { set; get; }
public string SaveFileToDB()
{
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"D:\\TinyShare\\App_Data\\TinyShareDB.mdf\";Integrated Security=True" + "Initial Catalog=TinyShareDB_log.ldf;Integrated Security=True;Pooling=False"))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UploadFile";
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@FileContent", FileContent);
cmd.Parameters.AddWithValue("@FileName", FileName);
cmd.Parameters.AddWithValue("@FileExtension", FileExtension);
cmd.Parameters.AddWithValue("@FileSize", FileExtension);
cmd.Parameters.AddWithValue("@FileContentType", FileExtension);
try
{
conn.Open();
cmd.ExecuteNonQuery();
return "File stored Successfully!!!";
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
conn.Close();
cmd.Dispose();
conn.Dispose();
}
}
}}
答案 0 :(得分:0)
USE statement
指定您的数据库。在创建之前检查您的对象是否存在。
use DbName
go
if object_id('YourProc') is null drop procedure YourProc
create YourProc...
如果将鼠标指针移到红色带下划线的文本上方,则会收到详细的错误说明。
您的ALTER
有下划线,因为您的对象可能尚未存在或无法访问此对象,因为您的脚本不知道您的程序在哪里。