Click here to Skip to main content
15,892,059 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how to paas a hidden link in a email Pin
David Mujica28-Jun-10 4:44
David Mujica28-Jun-10 4:44 
Questioninserting data to SQL via Storeprocedure(Please help) Pin
future383928-Jun-10 3:51
future383928-Jun-10 3:51 
AnswerRe: inserting data to SQL via Storeprocedure(Please help) Pin
JHizzle28-Jun-10 3:57
JHizzle28-Jun-10 3:57 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
future383928-Jun-10 4:15
future383928-Jun-10 4:15 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
JHizzle28-Jun-10 4:39
JHizzle28-Jun-10 4:39 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
future383928-Jun-10 15:48
future383928-Jun-10 15:48 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
JHizzle28-Jun-10 21:14
JHizzle28-Jun-10 21:14 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
future383929-Jun-10 14:41
future383929-Jun-10 14:41 
Hi, I really appreciate for you help.
I fixed up the code as you said.


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

namespace MvcApplication1.Models.Repository.DTO
{
    public class Item
    {
        //definition of class's fileds
        public int _id;
        public int _code;
        public string _description;
        public string _creator;
        public DateTime _created;


        //definition of properties
        public int Id
        {
            set 
            {
                _id = value;
                if (value < 0)
                    throw new ArgumentException(string.Format("Id should be greater than 0 !"));
            }
            get { return _id; }
        }
        public int Code
        {
            set { _code = value; }
            get { return _code; }
        }
        public string Description
        {
            set { _description = value; }
            get { return _description; }
        }
        public string Creator
        {
            set { _creator = value; }
            get { return _creator; }
        }
        public DateTime Created
        {
            set { _created = value; }
            get { return _created; }
        }

        //definiton of constructor
        public Item(int id, int code, string description, string creator, DateTime created)
        {
            this._id = id;
            this._code = code;
            this._description = description;
            this._creator = creator;
            this._created = created;
        }
    }
}


then in Model part in another class I write:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
using MvcApplication1.Models.Repository.DTO;

namespace MvcApplication1.Repository
{
    public class ItemRepository
    {
        //definition of fields
        private const string datasource =
            "Data Source= Dell\\SQLEXPRESS;Initial Catalog=DB_Furniture.mdf;Integrated Security=True;User Instance=True";

        private SqlConnection _connection;
        private SqlCommand _sqlcommand;
        private SqlDataReader _datareader;
        //definition of constructor
        public ItemRepository()
        {           
            // instantiate the connection
            _connection = new SqlConnection(datasource);     
        }
        //definition of insert method
        public void Insert(string code, string description, DateTime created, string creator)
        {
            //definition of SQl SP parameters
            _sqlcommand = new SqlCommand("Ins_item",_connection);
            _sqlcommand.CommandType = CommandType.StoredProcedure;
            _sqlcommand.Parameters.AddWithValue("@Code", code);
            _sqlcommand.Parameters.AddWithValue("@Description", description);
            _sqlcommand.Parameters.AddWithValue("@Created", created);
            _sqlcommand.Parameters.AddWithValue("@Creator", creator);
            _datareader = _sqlcommand.ExecuteNOnQuery();

        }
    }
}


the problem is here. I don't know what should I write in Controller part.I craete a controller class.
ing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MvcApplication1.Models.Repository.DTO;
using MvcApplication1.Models.Repository;
using MvcApplication1.Repository;
namespace MvcApplication1.Controllers
{
    public class FurnitureController : Controller
    {
        //
        // GET: /Furniture/

        public ActionResult Index()
        {
            return View();
        }

        //Get: /Furniture/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /Furniture/Create
        //  [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Craete(Item item)
        {
            try
            {
                ItemRepository ItemRep = new ItemRepository();
??????????????????????????????????????????????????????????????????????????????????
?
 ??
            }
            catch
            {
            }
        }

    } 
}


PLease heap me. its a week. I went through many samples and article on the internet.
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
JHizzle29-Jun-10 22:19
JHizzle29-Jun-10 22:19 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
future383930-Jun-10 5:26
future383930-Jun-10 5:26 
GeneralRe: inserting data to SQL via Storeprocedure(Please help) Pin
JHizzle30-Jun-10 6:17
JHizzle30-Jun-10 6:17 
QuestionProblem getting EditCommand event to fire in nested DataGrid Pin
Phillip Donegan28-Jun-10 2:39
Phillip Donegan28-Jun-10 2:39 
AnswerRe: Problem getting EditCommand event to fire in nested DataGrid Pin
Phillip Donegan29-Jun-10 3:17
Phillip Donegan29-Jun-10 3:17 
QuestionJavascript Method call!! Pin
sabby200628-Jun-10 0:31
sabby200628-Jun-10 0:31 
AnswerRe: Javascript Method call!! Pin
Sandeep Mewara28-Jun-10 0:47
mveSandeep Mewara28-Jun-10 0:47 
AnswerRe: Javascript Method call!! Pin
Venkatesh Mookkan28-Jun-10 1:26
Venkatesh Mookkan28-Jun-10 1:26 
AnswerRe: Javascript Method call!! Pin
Not Active28-Jun-10 2:52
mentorNot Active28-Jun-10 2:52 
QuestionTextBox Readonly Property Pin
Anurag Gandhi27-Jun-10 22:36
professionalAnurag Gandhi27-Jun-10 22:36 
AnswerRe: TextBox Readonly Property Pin
JHizzle27-Jun-10 23:39
JHizzle27-Jun-10 23:39 
AnswerRe: TextBox Readonly Property Pin
Brij27-Jun-10 23:48
mentorBrij27-Jun-10 23:48 
GeneralRe: TextBox Readonly Property Pin
Anurag Gandhi28-Jun-10 0:44
professionalAnurag Gandhi28-Jun-10 0:44 
GeneralRe: TextBox Readonly Property Pin
Brij28-Jun-10 4:45
mentorBrij28-Jun-10 4:45 
GeneralRe: TextBox Readonly Property Pin
Anurag Gandhi28-Jun-10 20:41
professionalAnurag Gandhi28-Jun-10 20:41 
AnswerRe: TextBox Readonly Property Pin
Sandeep Mewara28-Jun-10 0:46
mveSandeep Mewara28-Jun-10 0:46 
GeneralRe: TextBox Readonly Property Pin
Anurag Gandhi28-Jun-10 1:59
professionalAnurag Gandhi28-Jun-10 1:59 

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.