TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
aditya immadi
NA
205
71.6k
problem with image insert
Jul 30 2013 4:31 AM
Hai friends, i m trying to insert the imagepath in to database and images in projec folder.the images path are succesfully inserted in to database,but those images are not saved in my project folder ,if i'm trying to add the same images to the folder which is project ,then i got confirmaton message for re writting images.my code is like this..and every tym i run the following code the details are inserted in to databse twice
in aspx page
<%@ Page Title="newusercreation" Language="C#" MasterPageFile="~/master.Master" AutoEventWireup="true" CodeBehind="admim-newuser.aspx.cs" Inherits="ApComapaign.admim_newuser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="style1">
<tr>
<td style="width: 238px">
name</td>
<td>
<asp:TextBox ID="txtnameC" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
image</td>
<td>
<asp:FileUpload ID="FileUploadC" runat="server" />
</td>
</tr>
<tr>
<td style="width: 238px">
role</td>
<td>
<asp:DropDownList ID="ddlCRole" runat="server">
<asp:ListItem Text="MLA"></asp:ListItem>
<asp:ListItem Text="MP"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 238px">
party</td>
<td>
<asp:DropDownList ID="ddlCparty" runat="server">
<asp:ListItem Text="congress"></asp:ListItem>
<asp:ListItem Text="TDp"></asp:ListItem>
<asp:ListItem Text="YSRCP"></asp:ListItem>
<asp:ListItem Text="AIMIM"></asp:ListItem>
<asp:ListItem Text="loksatta"></asp:ListItem>
<asp:ListItem Text="CPI(M)"></asp:ListItem>
<asp:ListItem Text="TRS"></asp:ListItem>
<asp:ListItem Text="BJP"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 238px">
area</td>
<td>
<asp:TextBox ID="txtarea" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
district</td>
<td>
<asp:TextBox ID="txtdis" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
fblink</td>
<td>
<asp:TextBox ID="txtfb" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
blog</td>
<td>
<asp:TextBox ID="txtblog" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
twitter</td>
<td>
<asp:TextBox ID="txttwitt" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
wiki</td>
<td>
<asp:TextBox ID="txtwiki" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
website</td>
<td>
<asp:TextBox ID="txtweb" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 238px">
</td>
<td>
<asp:Button ID="btninsert" runat="server" Text="check and insert "
CausesValidation="False" onclick="btninsert_Click" />
</td>
</tr>
</table>
</asp:Content>
my .CS code is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
namespace ApComapaign
{
public partial class admim_newuser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btninsert_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUploadC.PostedFile.FileName);
FileUploadC.SaveAs(Server.MapPath("Images-candidates/" + filename));
string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(constring);
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "SP_detailsmain";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("name",txtnameC.Text);
cmd.Parameters.AddWithValue("image", FileUploadC.FileName);
cmd.Parameters.AddWithValue("role",ddlCRole.Text);
cmd.Parameters.AddWithValue("party",ddlCparty.Text);
cmd.Parameters.AddWithValue("area",txtarea.Text);
cmd.Parameters.AddWithValue("district",txtdis.Text);
cmd.Parameters.AddWithValue("fblink",txtfb.Text);
cmd.Parameters.AddWithValue("blog",txtblog.Text);
cmd.Parameters.AddWithValue("twitter",txttwitt.Text);
cmd.Parameters.AddWithValue("wiki",txtwiki.Text);
cmd.Parameters.AddWithValue("website",txtweb.Text);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
can any one tell me where is the bug is
Thanks and Regards
Reply
Answers (
38
)
how to disable gridview row when bindind?
Normalization in C# Windows Form Table