Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Code is here but data are not save into database

Item.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Item.aspx.cs" Inherits="Admin_Item" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">





<asp:Label ID="lblItemID" runat="server" Text="Item_ID" AssociatedControlID="txtItemID"> <asp:TextBox ID="txtItemID" runat="server">
<asp:Label ID="lblItemName" runat="server" Text="Item_Name" AssociatedControlID="txtItemName"> <asp:TextBox ID="txtItemName" runat="server">
<asp:Label ID="lblBrand" runat="server" Text="Brand" AssociatedControlID="txtBrand"> <asp:TextBox ID="txtBrand" runat="server">
<asp:Label ID="lblSize" runat="server" Text="Size" AssociatedControlID="txtSize"> <asp:TextBox ID="txtSize" runat="server">
<asp:Label ID="lblPrice" runat="server" Text="Price" AssociatedControlID="txtPrice"> <asp:TextBox ID="txtPrice" runat="server">
<asp:Label ID="lblImage" runat="server" Text="Image"> <asp:FileUpload ID="upImage" runat="server" />
<asp:Label ID="lblColor" runat="server" Text="Color" AssociatedControlID="txtColor"> <asp:TextBox ID="txtColor" runat="server">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />



<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Item_Master]">



Item.aspx.cs

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.Configuration;
using System.Data;

public partial class Admin_Item : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;

protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{

if (upImage.PostedFile != null && upImage.PostedFile.FileName != "")
{
byte[] imageSize = new byte[upImage.PostedFile.ContentLength];
HttpPostedFile uploadedImage = upImage.PostedFile;
uploadedImage.InputStream.Read(imageSize, 0, (int)upImage.PostedFile.ContentLength);

con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Online Shopping Portal.mdf;Integrated Security=True;User Instance=True");
con.Open();
String insertsql="INSERT Item_Master(Item_ID,Item_Name,Brand,Size,Price,Image,Color) Values ('" + txtItemID.Text + " ' ,'" + txtItemName.Text + "' , '"+txtBrand.Text +"','"+txtSize.Text +"','"+txtPrice.Text+"','"+upImage.FileBytes+"','"+txtColor.Text+"')";
cmd = new SqlCommand(insertsql, con);
con.Close();
txtItemID.Text = "";
txtItemName.Text = "";
txtBrand.Text = "";
txtSize.Text = "";
txtPrice.Text="";
txtColor.Text = "";
}
}
}

Database

Item_ID int Unchecked
Item_Name varchar(50) Checked
Brand varchar(50) Checked
Size int Checked
Price int Checked
Image image Checked
Color varchar(50) Checked
Unchecked
Posted
Updated 14-Feb-13 1:14am
v2

1 solution

Hi Please read this article it'll helpful for you.

http://www.dotnetcurry.com/ShowArticle.aspx?ID=129[^][]
 
Share this answer
 
Comments
Member 9815058 14-Feb-13 7:27am    
Thanks I try this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900