How to use submitChanges if i create programmatic control to collect data?

i created my Form programaticall using System.Reflaction. i want to add database with SubmitChanges. i will get data from whole txtbox and using any loop to fill Entity property. And than Submitchanges.

 public static void Save( PlaceHolder Holder)
        {


            if (Holder.Controls.Count > 0)
            {

                foreach (Control item in Holder.Controls)
                {
                    if (item is TextBox)
                    {
                        TextBox t1 = (TextBox)item;
                        if (t1.Text != "")
                        {
                            var engAccessData = new ENG_ACCESS()
                            {ENG_ACCESS_ACCESS_PANEL_NO = t1.Text //, don't any idea which Id is ok?

                        }
                    }
                }
            }
        }

i know this. But how can i add txtbox's text value to

  var stockMovement = new StockMovement
                        {
                           ENG_ACCESS_ACCESS_PANEL_NO = t1.Text,
                            TicketID = t2.Text,
                            ItemTypeNo = t3.Text,
                            StockCardID = t4.Text,
                            ItemID = t5.Text,
                            ItemBarcode = t6.Text,

                        };
                        stockMovementCtx.StockMovements.InsertOnSubmit(stockMovement);
                        stockMovementCtx.SubmitChanges();

alt text http://i47.tinypic.com/qstyj7.png

I NEED THIS LIKE ADO.NET:

public bool AccessProcess(string sp, ListDictionary ld, CommandType cmdType)
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["conn"].ToString());
SqlCommand cmd = new SqlCommand(sp, con);
try
{
con.Open();
cmd.CommandType = cmdType;
foreach (string ky in ld.Keys)
{
cmd.Parameters.AddWithValue(ky, ld[ky]);
}
cmd.ExecuteNonQuery();
}
finally
{
con.Dispose();
cmd.Dispose();
}
return true;
}
}

How to use like this linqto SQL ? or any method?

foreach (string ky in ld.Keys)
{
cmd.Parameters.AddWithValue(ky, ld[ky]);
}

Answers


What is your entity to add DB? this is the usage of adding entity to DB and submitchanges

TABBI_OUTGOING_MONEY_ORDER_DATA_TRANSFER_TRANSACTION newTransaction = new TABBI_OUTGOING_MONEY_ORDER_DATA_TRANSFER_TRANSACTION();
        newTransaction.TRANSACTION_ID = Guid.NewGuid();
        newTransaction.STATUS = Convert.ToInt32(TransactionStatus.DELETED);
        newTransaction.CREATED = DateTime.Now;
        newTransaction.CREATED_BY = userId;
        newTransaction.IS_KILLED = true;

        dataContext.TABBI_OUTGOING_MONEY_ORDER_DATA_TRANSFER_TRANSACTIONs.InsertOnSubmit(newTransaction);
        dataContext.SubmitChanges();

you can add more entity in a loop, after loop put the SubmitChanges() to push them all in DB

This maybe help to you

DataObjectModelDataContext dc = new DataObjectModelDataContext();

        var result = (from s in dc.YourTable select s).ToList();

        for (int i = 0; i < result.Count(); i++)
        {
            foreach (string ky in result[i].Key)
            {
                Item newItem = new Item();

                newItem.Key = ky;

                dc.YourTable.InsertOnSubmit(newItem);
            }
            dc.SubmitChanges();
        }

Need Your Help

Unable to change workspace settings (Server to Local) in TFS 2012

visual-studio visual-studio-2012 tfs tfs2012

I learnt about workspaces &amp; the advantages of local workspaces over server workspaces.

Custom servlet/jsp in Liferay portlet

java jsp servlets portlet liferay

I remember it was possible to add something like this to web.xml of a portlet and one could reach the jsp or servlet at http://host:8080/abcd/hw ....