Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Everybody,I am working on the small shopping website project and now I am working on the cart_page and I want to store the data using asp.net profile.But the problem is that when I run the project the data is shown during the debugging but it is not store to the 'ASPNETDB.MDF' database.So please help me:Here's below is my code:


C#
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            ((Label)DataList1.Controls[0].FindControl("LblName")).Text = (Profile.Name).ToString();
            ((Image)DataList1.Controls[0].FindControl("Image1")).ImageUrl = (Profile.ImageUrl).ToString();
            (((TextBox)DataList1.Controls[0].FindControl("TxtItem")).Text) = (Profile.Item).ToString();
            (((Label)DataList1.Controls[0].FindControl("LblPrice")).Text) = (Profile.Price).ToString();
            Profile.Save();
        }
      }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Profile.Name= ((Label)DataList1.Controls[0].FindControl("LblName")).Text;
        Profile.ImageUrl = ((Image)DataList1.Controls[0].FindControl("Image1")).ImageUrl;
        Profile.Item = int.Parse(((TextBox)DataList1.Controls[0].FindControl("TxtItem")).Text);
        Profile.Price = int.Parse(((Label)DataList1.Controls[0].FindControl("LblPrice")).Text);
        string ProductID = (Request.QueryString["ProductID"]);
        Profile.Save();
    }
}


and the code of web.config is here:

<connectionstrings>
   <add name="E-commerceConnectionString" connectionstring="Data Source=ps201\SQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True;User Id=Anoop Password=anoop@123;Pooling=False">
   providerName="System.Data.SqlClient" />
   </add></connectionstrings>
	<system.web>
    <authentication mode="Forms" />
    <anonymousidentification enabled="true" />
    <profile automaticsaveenabled="false">
      <properties>
        <add name="Id" type="int" allowanonymous="true" />
        <add name="Name" type="String" allowanonymous="true" />
        <add name="ImageUrl" type="String" allowanonymous="true" />
        <add name="Price" type="int" allowanonymous="true" />
        <add name="Item" type="int" allowanonymous="true" />
      </properties>
    </profile></system.web>
Posted
Updated 16-Oct-14 22:24pm
v3

1 solution

Where is the Query to store the data in the database table. Profile is used to store the personalized information regarding the page.
 
Share this answer
 
Comments
AnoopGharu 17-Oct-14 4:39am    
Thank you sir,but I don't use any kind of query to storing the database.Can you help me please how to add the query and please give me demo, because I am new to c#.net
MukeshSagar 17-Oct-14 4:57am    
SqlConnection con = new SqlConnection("server=servername;uid=sa;pwd=password;initial catalog=databasename");
String qry = "insert into tablename values(@id,@name,@imageurl,@price,@item)";
SqlCommand cmd = new SqlCommand(qry,com);
try
{
cmd.Paramaters.AddWithValues("@id",id);
cmd.Paramaters.AddWithValues("@name",name);
cmd.Paramaters.AddWithValues("@imageurl",imageurl);
cmd.Paramaters.AddWithValues("@price",price);
cmd.Paramaters.AddWithValues("@item",item);
con.Open();
cmd.ExecuteNonQuery();
}
catch(Exception ee)
{
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}

Also before that include the following namespaves:
1. System.Data
2. System.Data.SqlClient

and initialize the variables used
AnoopGharu 17-Oct-14 5:05am    
You are right sir,but I want to store the data in asp.net profile database not into the SQL server database.

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