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
Mohd Aamir
NA
68
4.6k
insert data with image into database
Oct 22 2018 3:38 AM
Hello Everyone..!
this is your friend Md Aamir
so let's point to the problem is that bfeore image option data waz being inserted but then i using image option so data is not being inserted m i doing wrong plz give solution if i m
i will be your thankfull
here you go for my cs code:
protected
void
btnbut_Click(
object
sender, EventArgs e)
{
if
(imageupload.HasFile)
{
string
strpath = System.IO.Path.GetExtension(imageupload.FileName);
if
(strpath !=
".jpg"
|| strpath !=
".jpeg"
|| strpath !=
".gif"
|| strpath !=
".png"
|| strpath !=
".PNG"
|| strpath !=
".GIF"
|| strpath !=
".JPEG"
|| strpath !=
".JPG"
)
{
// lblimgupl.Text = "Only jpg, png, gif,jpg or caps are accepted";
// ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Only image formats ('jpg, png, gif,jpg or caps are accepted ')", true);
}
else
{
con.Open();
SqlCommand cmd =
new
SqlCommand(
"insert2"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@category"
, ddlcategory.SelectedValue);
cmd.Parameters.AddWithValue(
"@name"
, txtname.Text);
cmd.Parameters.AddWithValue(
"@color"
, txtcolor.Text);
cmd.Parameters.AddWithValue(
"@price"
, txtprice.Text);
string
filename = DateTime.Now.Date.ToString(
"ddMMyyyy"
) + DateTime.Now.Minute + DateTime.Now.Millisecond + Path.GetExtension(imageupload.FileName);
imageupload.SaveAs(Server.MapPath(
"~/Upload/"
) + filename);
cmd.Parameters.AddWithValue(
"@Image1"
, filename);
lblimgupl.Text =
"Image successfully uploaded "
;
cmd.ExecuteNonQuery();
con.Close();
fill_grd();
}
}
}
here aspx page: -
<
%@ Page
Language
=
"C#"
AutoEventWireup
=
"true"
MasterPageFile
=
"~/admin/adminMasterPage.master"
CodeFile
=
"AddProducts.aspx.cs"
Inherits
=
"admin_AddProducts"
%
>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"Server"
>
<
asp:MultiView
ID
=
"MultiView1"
runat
=
"server"
>
<
asp:View
ID
=
"View1"
runat
=
"server"
>
<
div
>
<
asp:LinkButton
ID
=
"lbviewlist"
runat
=
"server"
OnClick
=
"lbviewlist_Click"
>
View Product List
</
asp:LinkButton
>
</
div
>
<
div
>
Select a Category
</
div
>
<
div
>
<
asp:DropDownList
ID
=
"ddlcategory"
runat
=
"server"
>
</
asp:DropDownList
>
</
div
>
<
div
>
Name:
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtname"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
Color
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtcolor"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
Price:
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtprice"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
Select Image:
</
div
>
<
div
>
<
asp:FileUpload
ID
=
"imageupload"
runat
=
"server"
/>
</
div
>
<
div
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
ForeColor
=
"Red"
>
</
asp:Label
>
</
div
>
<
div
>
<
asp:Label
ID
=
"lblimgupl"
runat
=
"server"
ForeColor
=
"Blue"
>
</
asp:Label
>
</
div
>
<
div
>
<
asp:Button
ID
=
"btnbut"
runat
=
"server"
Text
=
"Save"
OnClick
=
"btnbut_Click"
Width
=
"72px"
/>
</
div
>
</
asp:View
>
<
asp:View
ID
=
"View2"
runat
=
"server"
>
<
div
>
<
asp:LinkButton
ID
=
"lbback"
runat
=
"server"
OnClick
=
"lbback_Click"
>
Back
</
asp:LinkButton
>
</
div
>
<
asp:GridView
ID
=
"grd"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnRowEditing
=
"grd_RowEditing"
OnRowUpdating
=
"grd_RowUpdating"
OnRowCommand
=
"grd_RowCommand"
OnSelectedIndexChanged
=
"grd_SelectedIndexChanged"
>
<
Columns
>
<
asp:BoundField
DataField
=
"pid"
HeaderText
=
"ID"
/>
<
asp:TemplateField
HeaderText
=
"Cetagory"
>
<
ItemTemplate
>
<
%#Eval("category") %
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Name"
>
<
ItemTemplate
>
<
%#Eval("name") %
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Color"
>
<
ItemTemplate
>
<
%#Eval("color") %
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Price"
>
<
ItemTemplate
>
<
%#Eval("price") %
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Click_it"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lnkbtndelt"
runat
=
"server"
CommandName
=
"delt"
CommandArgument
=
'<%#Eval("pid") %>'
Text
=
"Delet"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Click_It"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lnkbtnedit"
runat
=
"server"
CommandName
=
"edt"
CommandArgument
=
'<%#Eval("pid") %>'
Text
=
"Edit"
OnClick
=
"btnedit_Click"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Click_It"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lnkbtnupd"
runat
=
"server"
CommandName
=
"upd"
CommandArgument
=
'<%#Eval("pid") %>'
Text
=
"update"
OnClick
=
"lnkbtnupd_Click"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Status"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lbtactive"
runat
=
"server"
Text
=
"Active"
Visible
=
"false"
CommandName
=
"Active"
OnClick
=
"lbtactive_Click"
>
</
asp:LinkButton
>
<
asp:LinkButton
ID
=
"ibinactive"
runat
=
"server"
Text
=
"Inactive"
CommandName
=
"Inactive"
OnClick
=
"ibinactive_Click"
>
</
asp:LinkButton
>
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
</
asp:GridView
>
</
asp:View
>
<
asp:View
ID
=
"View3"
runat
=
"server"
>
<
div
>
ID:
<
asp:Label
ID
=
"lblID"
runat
=
"server"
ForeColor
=
"#CC3300"
BorderColor
=
"Red"
>
</
asp:Label
>
</
div
>
<
div
>
<
asp:Label
ID
=
"lblmsg"
runat
=
"server"
ForeColor
=
"Blue"
>
</
asp:Label
>
</
div
>
<
div
>
<
asp:LinkButton
ID
=
"LinkButton1"
runat
=
"server"
OnClick
=
"lbviewlist_Click"
>
Back
</
asp:LinkButton
>
</
div
>
<
div
>
Select A Category
</
div
>
<
div
>
<
asp:DropDownList
ID
=
"ddlcetagory1"
runat
=
"server"
>
</
asp:DropDownList
>
</
div
>
<
div
>
Name:
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtname1"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
Color
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtcolor1"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
Price:
</
div
>
<
div
>
<
asp:TextBox
ID
=
"txtprice1"
runat
=
"server"
>
</
asp:TextBox
>
</
div
>
<
div
>
<
asp:Button
ID
=
"BtnSave"
runat
=
"server"
Text
=
"Save"
OnClick
=
"BtnSave_Click"
Width
=
"72px"
/>
</
div
>
</
asp:View
>
</
asp:MultiView
>
</
asp:Content
>
Reply
Answers (
3
)
generate a pdf in asp.net c#
Scorm With Asp.Net Core 2.0