views:

16

answers:

1

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

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]);
}
A: 

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();
        }
Serkan Hekimoglu
you don't understand me:) i am using linqtosql but my controls created programmatically. i have no idea how can i add database using linqtosql? Get data from txtbox which created diynamically
Phsika
yes I didn understand very well :} Now I got it, I dont know how to exactly to do that, but it should be same as normal text box adding. Your scenerio is : Adding textBoxes automaticly, and user filling them, and then pressing the button to submit their values to DB ??
Serkan Hekimoglu
Yes Serkan i need it. But i need using LinQtoSql. foreach (string ky in ld.Keys){cmd.Parameters.AddWithValue(ky, ld[ky]);}this is it. How to that in linqtosql
Phsika
can you write your Entity name with some properties? and textBox values which are equals to these entity properties? like Person newName = new Person();Person.Name, Person.LastName ... then I will write a code for you
Serkan Hekimoglu
i can do that serkan. But i have 70 columns so my entity 70. i created dynamically textbox i sholud add textbox value to enttiy in a loop?
Phsika
I dont think so you need a loop for it. In one buttonClick event, collect all textBox values and push it to entity.
Serkan Hekimoglu
my msn : [email protected]. Please add me serkan. i am turkish like you
Phsika
ok I will solve your question
Serkan Hekimoglu