if (uploadimg.PostedFile != null && uploadimg.PostedFile.FileName != "")
{
string img_id = "1";
byte[] myimage = new byte[uploadimg.PostedFile.ContentLength];
HttpPostedFile Image = uploadimg.PostedFile;
Image.InputStream.Read(myimage, 0, (int)uploadimg.PostedFile.ContentLength);
SqlConnection myConnection = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=eclass;Persist Security Info=True;integrated security = true");
SqlCommand storeimage = new SqlCommand("INSERT INTO ImageGallery " + "(img_id,image_Size,image_Content) " + " values (@img_id,@imagesize,@image)", myConnection);
storeimage.Parameters.AddWithValue("@img_id",img_id);
// storeimage.Parameters.Add("@id",SqlDbType.VarChar,100) = uploadimg.PostedFile.ContentType;
//storeimage.Parameters.Add('@id',id);
storeimage.Parameters.Add("@imagesize", SqlDbType.BigInt, 99999).Value = uploadimg.PostedFile.ContentLength;
storeimage.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage;
try
{
myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
}
catch (Exception e)
{
Response.Write(e.ToString());
}
}
какие изменения я должен сделать в своем коде c #, чтобы я мог избежать моего sql исключения из ограничения первичного ключа, так как я использовал свой триггер
создать триггер trig_image
в галерее изображений
После вставки
как начать
объявить @id int;
set @ id = 1;
обновить ImageGallery set img_id = 'img' + cast (@id as varchar (10))
set @ id = @ id + 1;
конец
идти
и столбцы: img_id varchar (50), image_size bigint, image_content image