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
Sayan Chatterjee
NA
22
2.9k
I want to store images in database tables
Aug 1 2017 2:59 PM
I have written a code as follows -
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.IO;
namespace
Shop
{
public
partial
class
addimage : System.Web.UI.Page
{ SqlConnection con =
new
SqlConnection(
"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Sayan\\Documents\\Saanvi.mdf;Integrated Security=True;Connect Timeout=30"
);
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
Buttonuploadimage_Click(
object
sender, EventArgs e)
{
FileUpload f =
new
FileUpload();
if
(f.HasFile)
{
string
str = f.FileName;
f.PostedFile.SaveAs(Server.MapPath(
"."
) +
"//Images//"
+ str);
string
path =
"~//Images//"
+ str.ToString();
con.Open();
SqlCommand cmd=
new
SqlCommand(
"Insert into Images values('"
+ path +
"')"
, con);
cmd.ExecuteNonQuery();
con.Close();
Labeluploadimage.Text =
"Image uploaded successfully"
;
}
else
{
Labeluploadimage.Text =
"Pls. upload an image"
;
}
However, I see that the if statement is not executed and always the statement under the else statement is executed. Is this something to do with the Button click event handler? I have a "upload image" button and a "upload" control used from the toolbox. I have an "Images" folder under solution explorer, where I have already kept few pics.
Reply
Answers (
2
)
C# error after install project
Regarding private and public key encryption