ASPX Code :
Image is not getting uploaded in Database. Please Help.
<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="server">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Testimonials</h1>
<div class="table-responsive">
<div class="mysidebar-ele">
<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="Name"></dx:ASPxLabel>
</div>
<div class="mysidebar-ele">
<dx:ASPxTextBox ID="txt_Name" runat="server" Width="170px"></dx:ASPxTextBox>
</div>
<div class="mysidebar-ele">
<dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="City"></dx:ASPxLabel>
</div>
<div class="mysidebar-ele">
<asp:DropDownList ID="ddl_City" Width="20%" DataSourceID="DS_City" CssClass="form-control" DataTextField="CityName"
DataValueField="CityId" AutoPostBack="true" runat="server" ToolTip="City" Font-Size="10" AppendDataBoundItems="true"/>
<asp:SqlDataSource ID="DS_City" runat="server" ConnectionString="<%$ ConnectionStrings:dbconn %>" SelectCommand="sp_city" SelectCommandType="StoredProcedure" />
</div>
<div class="mysidebar-ele">
<dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="Deal_Details"></dx:ASPxLabel>
</div>
<div class="mysidebar-ele">
<dx:ASPxTextBox ID="txt_DealDetails" runat="server" Width="170px"></dx:ASPxTextBox>
</div>
<div class="mysidebar-ele">
<dx:ASPxLabel ID="ASPxLabel4" runat="server" Text="Comments"></dx:ASPxLabel>
</div>
<div class="mysidebar-ele">
<textarea style="width:350px; height:100px;" placeholder="Enter Comment" runat="server" id="txt_comments"></textarea>
</div>
<%-- <div class="mysidebar-ele">
<dx:ASPxLabel ID="ASPxLabel5" runat="server" Text="Upload Photo"></dx:ASPxLabel>
</div>--%>
<div class="mysidebar-ele">
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" UploadMode="Auto" Width="280px"
ShowProgressPanel="true" ShowUploadButton="true" >
<ValidationSettings MaxFileSize="4194304" AllowedFileExtensions=".jpg,.jpeg,.gif,.png" /></dx:ASPxUploadControl>
</div>
<div style="text-align:center">
<div class="mysidebar-ele">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Add" OnClick="ASPxButton1_Click"></dx:ASPxButton>
</div>
<p>
<asp:Label ID="lbl_result" runat="server" Text=""></asp:Label>
</p>
</div>
</div>
</div>
</asp:Content>
C# (BackEnd Code) :
protected void ASPxButton1_Click(object sender, EventArgs e)
{
if (!IsPostBack == false)
{
if (string.IsNullOrEmpty(txt_Name.Text))
{
lbl_result.Text = "Name Required !!";
return;
}
if (string.IsNullOrEmpty(txt_DealDetails.Text))
{
lbl_result.Text = "Deal Details Required !!";
return;
}
if (string.IsNullOrEmpty(txt_comments.Value))
{
lbl_result.Text = "Comment Required !!";
return;
}
//protected void UploadTest()
//{
//string filePath = Server.MapPath("~/Brochures/" + UploadTest.FileName);
//UploadTest.SaveAs(filePath);
//}
//if (string.IsNullOrEmpty(ASPxUploadControl1.))
//{
// lbl_result.Text = "Comment Required !!";
// return;
//}
string cons = WebConfigurationManager.ConnectionStrings["dbconn"].ToString();
SqlConnection conn = new SqlConnection(cons);
conn.Open();
SqlCommand cmd = new SqlCommand("sp_add_testimonials", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@state", "0");
cmd.Parameters.AddWithValue("@Name", txt_Name.Value);
cmd.Parameters.AddWithValue("@City", ddl_City.ToString());
cmd.Parameters.AddWithValue("@Deal_Details", txt_DealDetails.Value);
cmd.Parameters.AddWithValue("@Comments", txt_comments.Value);
cmd.Parameters.AddWithValue("@photo", ASPxUploadControl1.SaveAs("../../images/.jpg"));
cmd.ExecuteNonQuery();
conn.Close();
}
}