I am quite new to ASP.NET and I am making my first application for my school project and I have one problem.
I have my database for adding files and pictures. I used a SqlDataSource and DataList, so I generate insert, update and delete automatically. In code-behind C#, I wrote code for adding images directly to database and file with path that goes to database, but I don't know how to add value (path) to parameter so it could all be saved together. What command should I use?
Maybe it is stupid question, but I don't have anyone to ask. Sorry If my code is a little bit funny looking here in this windowenter code here
Here is my C#
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
FileUpload kontrola = (FileUpload)FormView1.FindControl("FileUpload2");
if (kontrola.PostedFile != null && kontrola.PostedFile.FileName != "")
{
BinaryReader reader = new BinaryReader(kontrola.PostedFile.InputStream);
myImage = reader.ReadBytes(kontrola.PostedFile.ContentLength);
}
System.Data.SqlClient.SqlParameter uploadData =
new System.Data.SqlClient.SqlParameter("@image",System.Data.SqlDbType.Image);
uploadData.Value = myImage;
e.Command.Parameters.Add(uploadData);
FileUpload kontrola2 = (FileUpload)FormView1.FindControl("FileUpload1");
//Get Filename from fileupload control
string filename = Path.GetFileName(kontrola2.PostedFile.FileName);
//Save images into Images folder
kontrola2.SaveAs(Server.MapPath("~/files/" + kontrola2.FileName));
string valp = "files/" + kontrola2.FileName; // I am not sure if this is right
//e.Command.Parameters.Add["@data_file"].Value = valp; // this is not right, but this part I don't know
}
and this is my markup in aspx.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:repository_dbConnectionString %>"
SelectCommand="SELECT * FROM [data]"
DeleteCommand="DELETE FROM [data] WHERE [id] = @id"
InsertCommand="INSERT INTO [data] ([data_set_name], [abstract], [source], [multivariate], [unvariate], [sequentional], [time_series], [text], [domain_theory], [clasification], [regression], [clustering], [casual_discovery], [categorical], [integer], [real], [life_sciences], [physical_sciences], [cs_engineering], [social_sciences], [business], [game], [other], [matrix], [non_matrix], [yes], [no], [num_istances], [num_attributes], [relevant_info], [attribute_info], [relevant_papers], [citation_request], [data_file], [image], [date], [approval]) VALUES (@data_set_name, @abstract, @source, @multivariate, @unvariate, @sequentional, @time_series, @text, @domain_theory, @clasification, @regression, @clustering, @casual_discovery, @categorical, @integer, @real, @life_sciences, @physical_sciences, @cs_engineering, @social_sciences, @business, @game, @other, @matrix, @non_matrix, @yes, @no, @num_istances, @num_attributes, @relevant_info, @attribute_info, @relevant_papers, @citation_request, @data_file, @image, GetDate(), @approval)"
UpdateCommand...
oninserting="SqlDataSource1_Inserting">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="data_set_name" Type="String" />
<asp:Parameter Name="abstract" Type="String" />
<asp:Parameter Name="source" Type="String" />
<asp:Parameter Name="multivariate" Type="Boolean" />
<asp:Parameter Name="unvariate" Type="Boolean" />
<asp:Parameter Name="sequentional" Type="Boolean" />
<asp:Parameter Name="time_series" Type="Boolean" />
<asp:Parameter Name="text" Type="Boolean" />
<asp:Parameter Name="domain_theory" Type="Boolean" />
<asp:Parameter Name="clasification" Type="Boolean" />
<asp:Parameter Name="regression" Type="Boolean" />
<asp:Parameter Name="clustering" Type="Boolean" />
<asp:Parameter Name="casual_discovery" Type="Boolean" />
<asp:Parameter Name="categorical" Type="Boolean" />
<asp:Parameter Name="integer" Type="Boolean" />
<asp:Parameter Name="real" Type="Boolean" />
<asp:Parameter Name="life_sciences" Type="Boolean" />
<asp:Parameter Name="physical_sciences" Type="Boolean" />
<asp:Parameter Name="cs_engineering" Type="Boolean" />
<asp:Parameter Name="social_sciences" Type="Boolean" />
<asp:Parameter Name="business" Type="Boolean" />
<asp:Parameter Name="game" Type="Boolean" />
<asp:Parameter Name="other" Type="Boolean" />
<asp:Parameter Name="matrix" Type="Boolean" />
<asp:Parameter Name="non_matrix" Type="Boolean" />
<asp:Parameter Name="yes" Type="Boolean" />
<asp:Parameter Name="no" Type="Boolean" />
<asp:Parameter Name="num_istances" Type="Int32" />
<asp:Parameter Name="num_attributes" Type="Int32" />
<asp:Parameter Name="relevant_info" Type="String" />
<asp:Parameter Name="attribute_info" Type="String" />
<asp:Parameter Name="relevant_papers" Type="String" />
<asp:Parameter Name="citation_request" Type="String" />
<asp:Parameter Name="data_file" Type="String" />
<asp:Parameter DbType="Date" Name="date" />
<asp:Parameter Name="approval" Type="Boolean" />
</InsertParameters>