Click here to Skip to main content
15,889,742 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionhow to save both text and image together Pin
Dhyanga21-Sep-10 10:05
Dhyanga21-Sep-10 10:05 
AnswerRe: how to save both text and image together Pin
Abhijit Jana21-Sep-10 10:44
professionalAbhijit Jana21-Sep-10 10:44 
GeneralRe: how to save both text and image together Pin
Dhyanga21-Sep-10 11:31
Dhyanga21-Sep-10 11:31 
GeneralRe: how to save both text and image together Pin
Abhijit Jana21-Sep-10 12:11
professionalAbhijit Jana21-Sep-10 12:11 
GeneralRe: how to save both text and image together Pin
Dhyanga21-Sep-10 12:24
Dhyanga21-Sep-10 12:24 
GeneralRe: how to save both text and image together Pin
Anurag Gandhi22-Sep-10 1:58
professionalAnurag Gandhi22-Sep-10 1:58 
GeneralRe: how to save both text and image together Pin
Dhyanga22-Sep-10 2:48
Dhyanga22-Sep-10 2:48 
Questionerror in inserting data(pls help) Pin
future383921-Sep-10 6:35
future383921-Sep-10 6:35 
hello,

I have a table in database which is as below:
CREATE TABLE item(
         id INT,
         itemModel VARCHAR(100),
         name VARCHAR(100),
         description VARCHAR(100),
         created VARCHAR(100),
         creator VARCHAR(100),


then in my BusinessObject Layer I have this class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;

namespace WebApplication1.Repository.BusinessObject
{
    public class Items
    {
        private int _id = -1;
        private string _model = string.Empty;
        private string _name = string.Empty;
        private string _description = string.Empty;
        private DateTime _created = DateTime.MinValue;
        private string _ctreator = string.Empty;


        [DataObjectFieldAttribute(true,true,false)]
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }

        public string Model
        {
            set { _model = value; }
            get { return _model; }
        }

        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }

        public string Description
        {
            set { _description = value; }
            get { return _description; }
        }

        public DateTime Created
        {
            set { _created = value; }
            get { return _created; }
        }

        public string Creator
        {
            set { _ctreator = value; }
            get { return _ctreator; }
        }


        public Items(int id, string model, string name, string description,
                        DateTime created, string ctreator)
        {
            this._id = id;
            this._model = model;
            this._name = name;
            this._description = description;
            this._created = created;
            this._ctreator = Creator;
        }
    }
}


then I create another layer called DataAccess define this class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WebApplication1.Repository.BusinessObject;
using System.Data.Common;
using System.Data.SqlClient;




namespace WebApplication1.Repository.DataAccessLayer
{
    public class ItemsDB
    {
        public static int Save(Items NewItems)
        {
            int Result = 0;
            SqlConnection MyConnection = new SqlConnection(ConfigurationManager.
                                     ConnectionStrings["ConnectionString"].ConnectionString);
            SqlCommand MyCommand = new SqlCommand("SprocInsertUpdateSingleItem",
                                     MyConnection);
            MyCommand.CommandType = CommandType.StoredProcedure;
            if (NewItems.ID == -1)
            {
                MyCommand.Parameters.AddWithValue("@id", DBNull.Value);
            }
            else
            {
                MyCommand.Parameters.AddWithValue("@id", NewItems.ID);
            }
            MyCommand.Parameters.AddWithValue("@ItemModel", NewItems.Model);
            MyCommand.Parameters.AddWithValue("@Name", NewItems.Name);
            MyCommand.Parameters.AddWithValue("@Description", NewItems.Description);
            MyCommand.Parameters.AddWithValue("@Created", NewItems.Created);
            MyCommand.Parameters.AddWithValue("@Creator", NewItems.Creator);

            DbParameter returnValue;
            returnValue = MyCommand.CreateParameter();
            returnValue.Direction = ParameterDirection.ReturnValue;
            MyCommand.Parameters.Add(returnValue);

            MyConnection.Open();
            MyCommand.ExecuteNonQuery();

            Result = Convert.ToInt32(returnValue.Value);
            MyConnection.Close();

            return Result;
        }
    }
}


next, in BusinessLogicLayer I try to interact with database
using System;
using System.Collections.Generic;
using System.Web;
using System.ComponentModel;
using System.Transactions;

using WebApplication1.Repository.DataAccessLayer;
using WebApplication1.Repository.BusinessObject;

namespace WebApplication1.Repository.BusinessLayer
{
    public class ItemsManager
    {
        [DataObjectMethod(DataObjectMethodType.Update,true)]
        public static int Save(Items NewItem)
        {
            using (TransactionScope MyTransactioScope = new TransactionScope())
            {
                int ItemId = ItemsDB.Save(NewItem);

                foreach ( Items itemId in NewItem.ID)
                {
                    itemId.ID = ItemId;
                    ItemsDB.Save(itemId);
                }
                NewItem.ID = ItemId;

                MyTransactioScope.Complete();

                return ItemId;                
            }

        }
    }
}


after I run the program I get this error:
<br />
  foreach statement cannot operate on variables of type 'int' because 'int' does not contain a public definition for 'GetEnumerator'	<br />


Do you recken the problem is regarding database design?
I get this idea from the following link
http://www.wewill.cn/n2020c22.aspx



I really appreciate if someone help me in this matter.


is there anyway to put my project here?then people can see it and maybe help me.
AnswerRe: error in inserting data(pls help) Pin
Karthik. A23-Sep-10 8:23
Karthik. A23-Sep-10 8:23 
Questionmobile page width Pin
Jassim Rahma21-Sep-10 5:58
Jassim Rahma21-Sep-10 5:58 
AnswerRe: mobile page width Pin
NeverHeardOfMe21-Sep-10 6:33
NeverHeardOfMe21-Sep-10 6:33 
Questionproblem in generating New Empty Datarow with Empty TextBoxes in Gridview on ButtonClick Pin
Amit Spadez21-Sep-10 0:01
professionalAmit Spadez21-Sep-10 0:01 
AnswerRe: problem in generating New Empty Datarow with Empty TextBoxes in Gridview on ButtonClick Pin
Not Active21-Sep-10 2:27
mentorNot Active21-Sep-10 2:27 
QuestionDataObjectMethod Pin
future383920-Sep-10 14:31
future383920-Sep-10 14:31 
AnswerRe: DataObjectMethod Pin
Luc Pattyn20-Sep-10 15:16
sitebuilderLuc Pattyn20-Sep-10 15:16 
Questionnested user controls Pin
Dhyanga20-Sep-10 3:04
Dhyanga20-Sep-10 3:04 
AnswerRe: nested user controls Pin
Dhyanga20-Sep-10 5:56
Dhyanga20-Sep-10 5:56 
AnswerRe: nested user controls Pin
Sandeep Mewara20-Sep-10 7:01
mveSandeep Mewara20-Sep-10 7:01 
GeneralRe: nested user controls Pin
Dhyanga20-Sep-10 7:15
Dhyanga20-Sep-10 7:15 
GeneralRe: nested user controls Pin
Sandeep Mewara20-Sep-10 7:15
mveSandeep Mewara20-Sep-10 7:15 
AnswerRe: nested user controls Pin
Dhyanga20-Sep-10 7:55
Dhyanga20-Sep-10 7:55 
QuestionWebUserControl, UpadtePanel And JavaScript Problem Pin
jitendrafaye19-Sep-10 18:06
jitendrafaye19-Sep-10 18:06 
AnswerRe: WebUserControl, UpadtePanel And JavaScript Problem Pin
david vermeulen28-Sep-10 20:09
david vermeulen28-Sep-10 20:09 
QuestionCan not reference text value in footer of Gridview control [modified] Pin
rhicks5419-Sep-10 14:39
rhicks5419-Sep-10 14:39 
Questionquestion about IsMobileDevice Pin
Jassim Rahma19-Sep-10 5:48
Jassim Rahma19-Sep-10 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.