开发者

How can I save binary Image using C1Upload to the SQL Database?

开发者 https://www.devze.com 2023-04-01 20:55 出处:网络
Is there a way to save image to the database usingC1Upload. I am only using Asp.Net, C#.Net for the programming and Javascr开发者_如何学Cipt of needed and nothing else. Is there a way in saving withou

Is there a way to save image to the database using C1Upload. I am only using Asp.Net, C#.Net for the programming and Javascr开发者_如何学Cipt of needed and nothing else. Is there a way in saving without using Silverlight?

Thanks

-Mush


You you do this by reading the bytes of uploaded file in C1Upload1_Uploaded event.

    protected void C1Upload1_Uploaded(object sender, UploadedFileEventArgs e)
    {
        //Read uploaded file stream
        C1FileInfo file = e.UploadedFile;
        byte[] buffer = new byte[file.Size];
        file.GetStream().Read(buffer, 0, file.Size);
        file.GetStream().Close();

        //Save file bytes to database
        System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection("sqlConnectionString");
        System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("INSET INTO yourtable(image) VALUES(@image)", sqlConn);
        sqlCmd.Parameters.AddWithValue("@image", buffer);
        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();
        sqlConn.Close();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消