public void InsertAnImage(Guid i)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
Stream stream = FileUpload1.FileContent;
StreamReader reader = new StreamReader(stream);
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection conn = new SqlConnection(AllQuestionsPresented.connectionString))
{
// sample query with parameters to insert into db
string sqlQuery = "INSERT INTO [UserProfile] (UserID, Picture) Values (@userId, @picture)";
// conn is your db connection
SqlCommand command = new SqlCommand(sqlQuery, conn);
// creating parameters
SqlParameter paramId = new SqlParameter("@userId", SqlDbType.Int, 4);
paramId.Value = 45;
// you picture parameter, and assigning its the value
SqlParameter paramPicture = new SqlParameter("@picture", SqlDbType.Binary, myImage.Length);// red line here
paramPicture.Value = myImage;// red line here
// adding params to command
command.Parameters.Add(paramId);
command.Parameters.Add(paramPicture);
// then execute your command
command.ExecuteNonQuery();
}
}
Как поместить в базу данных потоковый считыватель вместо считывателя Filestream?