如何将图像从屏幕保存到新的数据库记录

时间:2016-06-02 18:58:19

标签: c# asp.net

我有一条存储在SQL中的记录,其中一个图像文件存储为一列数据。

在用于制作"关闭副本的表单上#34;记录的更改(更改一个或两个字段的内容,但保持其余字段相同)我正在显示图像供用户查看。

如何将此图像控件的内容保存到新数据库记录中? 现在保存工作,除了我必须保存int值0代替图像文件内容。

保存查询:

protected void ButtonUpload_Click(object sender, EventArgs e)
    {
        string vAuthor = (CloneRecord.FindControl("txt_author") as TextBox).Text;
        string vDate = (CloneRecord.FindControl("txtDate") as TextBox).Text;
        string vStem = (CloneRecord.FindControl("txt_stem") as TextBox).Text;
        string vRespA = (CloneRecord.FindControl("txt_RespA") as TextBox).Text;
        string vRespB = (CloneRecord.FindControl("txt_RespB") as TextBox).Text;
        string vRespC = (CloneRecord.FindControl("txt_RespC") as TextBox).Text;
        string vRespD = (CloneRecord.FindControl("txt_RespD") as TextBox).Text;
        string vRespE = (CloneRecord.FindControl("txt_RespE") as TextBox).Text;
        string vAnswer = (CloneRecord.FindControl("txt_Answer") as DropDownList).SelectedValue;
        string vCritique = (CloneRecord.FindControl("txt_Critique") as TextBox).Text;
        string vKeyLO = (CloneRecord.FindControl("txt_KeyObjective") as TextBox).Text;
        string vReference = (CloneRecord.FindControl("txt_References") as TextBox).Text;
        int vPractice1 = Convert.ToInt32((CloneRecord.FindControl("DDPractice1") as DropDownList).SelectedValue);
        int vPractice2 = Convert.ToInt32((CloneRecord.FindControl("DDPractice2") as DropDownList).SelectedValue);
        int vPractice3 = Convert.ToInt32((CloneRecord.FindControl("DDPractice3") as DropDownList).SelectedValue);
        int vPractice4 = Convert.ToInt32((CloneRecord.FindControl("DDPractice4") as DropDownList).SelectedValue);
        string vImage1 = (CloneRecord.FindControl("Image1Content") as TextBox).Text;
        string vImage2 = (CloneRecord.FindControl("Image2Content") as TextBox).Text;
        string vImage3 = (CloneRecord.FindControl("Image3Content") as TextBox).Text;
        string vImage4 = (CloneRecord.FindControl("Image4Content") as TextBox).Text;
        string vIName1 = (CloneRecord.FindControl("Image1Name") as TextBox).Text;
        string vIName2 = (CloneRecord.FindControl("Image2Name") as TextBox).Text;
        string vIName3 = (CloneRecord.FindControl("Image3Name") as TextBox).Text;
        string vIName4 = (CloneRecord.FindControl("Image4Name") as TextBox).Text;
        string vQuestionID = (CloneRecord.FindControl("IsCloneOf") as TextBox).Text;
        int vImageFile1 = 0;
        int vImageFile2 = 0;
        int vImageFile3 = 0;
        int vImageFile4 = 0;

        {
            string constr = ConfigurationManager.ConnectionStrings["CS1"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                string query = "insert into Questions values (@Author, @ImageFile, @Image1Content, @Image1Name, @ImageFile2, @Image2Content, @Image2Name, @ImageFile3, @Image3Content, @Image3Name, @ImageFile4, @Image4Content, @Image4Name,@SubmitDate, @Stem, @RespA, @RespB, @RespC, @RespD, @RespE, @Answer, @Critique, @KeyObjective, @Reference, @PracticeArea1, @PracticeArea2, @PracticeArea3, @PracticeArea4, @IsCloneOf)";
                using (SqlCommand cmd = new SqlCommand(query))

1 个答案:

答案 0 :(得分:0)

您可以存储为BLOB (Binary Large Object),用于存储非结构化数据,例如图像和文档。