sbornstein2
asked on
Replacing Stored Proc Parameter each time
Hi all I have a stored proc and code that sets parameters etc. I need to use the same insert 10 times and replace two parameters each time. How do I do that? For example,
command.Parameters.Add("@M YID", SqlDbType.Int).Value = 25;
command.Parameters.Add("@M YHRS", SqlDbType.Int).Value = 6;
then I run it. Next lines I need to replace the above values?
command.Parameters.Add("@M YID", SqlDbType.Int).Value = 87;
command.Parameters.Add("@M YHRS", SqlDbType.Int).Value = 43;
command.Parameters.Add("@M
command.Parameters.Add("@M
then I run it. Next lines I need to replace the above values?
command.Parameters.Add("@M
command.Parameters.Add("@M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
can u give me more description on what is ur value (@MYID, @MYHRS)is taken from? hardcoded ID for each 10 textbox(user input) ? 13 records? Sorry, i am not getting the picture clear enough... maybe i need to wear thicker glasses (getting old...) .. :)
ASKER
no not at all. thanks. What I have is 10 textboxes that are setup like so:
txtGrp2Box1, txtGrp2Box2, txtGrp2Box3......txtGrp2Bo x10
so I can probably iterate through that 10 times with a for loop or something and insert the records for 10 times. But then I have to pass in a hardcoded ID the @MYID. Maybe I can use some type of array where I can setup the ID's for each insert. For example,
txtGrp2Box1.Text = 10 for @MyHrs
txtGrp2Box2.Text = 30 for @MyHrs
But the @MYID I need to pass in for each hardcoded such as 20 might be the ID for txtGrp2Box1 I need to pass with it. Problem is we have this combination table that stores an ID for a combination of 3 fields. Well it is a real pain to have to go dig through and pass all the 3 parameters for the combination so I want to pass the ID field number instead. But it is an identity column I need to look up.
txtGrp2Box1, txtGrp2Box2, txtGrp2Box3......txtGrp2Bo
so I can probably iterate through that 10 times with a for loop or something and insert the records for 10 times. But then I have to pass in a hardcoded ID the @MYID. Maybe I can use some type of array where I can setup the ID's for each insert. For example,
txtGrp2Box1.Text = 10 for @MyHrs
txtGrp2Box2.Text = 30 for @MyHrs
But the @MYID I need to pass in for each hardcoded such as 20 might be the ID for txtGrp2Box1 I need to pass with it. Problem is we have this combination table that stores an ID for a combination of 3 fields. Well it is a real pain to have to go dig through and pass all the 3 parameters for the combination so I want to pass the ID field number instead. But it is an identity column I need to look up.
ok. If i'm getting it right, u want to have 10 textbox on ur form, each textbox will be assigned a unique harcoded ID which will be the value of @MYID.
Then the textbox will be receiving input from user which is the value of @MYHRS.
Am i rigth?
Then the textbox will be receiving input from user which is the value of @MYHRS.
Am i rigth?
Assumming i'm right...
instantiate an array of textbox, and Id (which store the hardcoded Id).
private const int COUNT = 10;
private TextBox[] txtInput = new TextBox[COUNT];
private int[] ID = new int[COUNT];
assign the ID array with ur hardcoded ID (Or u lookup in db, maybe).
put the textbox to the form. (arrange the coordinate urself...)
for (i = 0; i < TEXTBOX_COUNT; ++i)
{
txtInput[i] = new TextBox();
txtInput[i].Bounds = new Rectangle(20, 20 + (20 * i), 100, 100);
txtInput[i].Parent = this;
}
Then when u use the procedure call, u may do like this...
for (int i = 0; i < COUNT; ++i)
{
command.Parameters["@MYID" ].Value = ID[i];
command.Parameters.["@MYHR S"].Value = Convert.ToInt32(txtInput[i ].Text);
command.ExecuteNonQuery();
}
hope it helps...
instantiate an array of textbox, and Id (which store the hardcoded Id).
private const int COUNT = 10;
private TextBox[] txtInput = new TextBox[COUNT];
private int[] ID = new int[COUNT];
assign the ID array with ur hardcoded ID (Or u lookup in db, maybe).
put the textbox to the form. (arrange the coordinate urself...)
for (i = 0; i < TEXTBOX_COUNT; ++i)
{
txtInput[i] = new TextBox();
txtInput[i].Bounds = new Rectangle(20, 20 + (20 * i), 100, 100);
txtInput[i].Parent = this;
}
Then when u use the procedure call, u may do like this...
for (int i = 0; i < COUNT; ++i)
{
command.Parameters["@MYID"
command.Parameters.["@MYHR
command.ExecuteNonQuery();
}
hope it helps...
ASKER
you got it :)
ASKER
I will try that thanks so much Jeff :)
ASKER