Dear all I am displaying an image in my gridview, this image is saved in database in varbinary format, with its content type and image name. And my image in gridview is displaying perfect, now I want to insert this same image from gridview to another table from the button click outside the gridview, How do I achieve this can anyone please guide me? I tried achieving it by receiving this image data from gridview such as Varbinary data - which is an image in database and content type and imagename into textbox but it thorws an error "Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query"
NavigateUrl='' runat="server">
CommandName='<%# Eval("Id") %>' CommandArgument='<%# Eval("ImageName") %>' />
foreach (GridViewRow row1 in gvImage.Rows)
{
if (row1.RowType == DataControlRowType.DataRow)
{
// txtFileType
// txtBData
// txtImageName
TextBox txtFileType, txtBData, txtImageName;
txtFileType = (row1.Cells[1].FindControl("txtFileType") as TextBox);
txtBData = (row1.Cells[1].FindControl("txtBData") as TextBox);
txtImageName = (row1.Cells[1].FindControl("txtImageName") as TextBox);
string constr = ConfigurationManager.ConnectionStrings["CONNECTION"].ConnectionString;
using (SqlConnection con8 = new SqlConnection(constr))
{
string query = "insert into SShare (FId,UDetails,ShareBy,ShareByUserId,BData,FileType,ImageName) values(@FId,@UDetails,@ShareBy,@ShareByUserId,@BData,@FileType,@ImageName)";
using (SqlCommand cmd8 = new SqlCommand(query))
{
cmd8.Parameters.AddWithValue("@FId", txt_Tester.Text);
cmd8.Parameters.AddWithValue("@UDetails", TextBox1.Text);
cmd8.Parameters.AddWithValue("@ShareBy", txt_StaffId.Text);
cmd8.Parameters.AddWithValue("@ShareByUserId", txt_Employee.Text);
cmd8.Parameters.AddWithValue("@BData", txtBData.Text);
cmd8.Parameters.AddWithValue("@FileType", txtFileType.Text);
cmd8.Parameters.AddWithValue("@ImageName", txtImageName.Text);
con8.Open();
// cmd8.ExecuteNonQuery();
this.ExecuteQuery(cmd8, "SELECT");
con8.Close();
}
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dharam RaiPosted Apr 19, 2017, 12:34 PM
Nilesh JadavPosted Apr 17, 2017, 9:58 AM
Might that help !