|
Thanks for your Prompt Reply sir
I have made the changes in the code as you have suggested as shown:
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=localhost;Initial Catalog=InkDb;Integrated Security=True;Persist Security Info=True;Packet Size=4096";
string qry = "Insert into beziertable values(@strokeIndex,@cuspIndex,@BezierCusp)";
SqlCommand sqlInsertCmd = new SqlCommand(qry, con);
sqlInsertCmd.CommandText = qry;
sqlInsertCmd.CommandType = CommandType.Text;
int count;
int i;
sqlInsertCmd.Parameters.AddWithValue("@strokeIndex", mInkoverlay.Ink.Strokes.IndexOf(stroke));
int cus;
cus = Convert.ToInt16(stroke.BezierCusps.GetValue(0));
sqlInsertCmd.Parameters.AddWithValue("@cuspIndex", cus);
// I have made the changes by making declaration outside the loop as sqlInsertCmd.Parameters.AddWithValue("@BezierCusp", val);//My loop works acuurate But as my loop execute i<=100 times and it come out of loop and the value which my variable "val" carry will get inserted into the database , but i want all the values of "val" for each iteration till i=0 to i>=100, But the last value of "val" get inserted , i dont want this , i want all the values of array of the Stroke.GetPoint(i).X. Please suggest me the solution to rectify the Problem///
for (i = 0; i <=100 i = i + 1)
{
val=stroke.GetPoint(i).X;
}
sqlInsertCmd.Parameters.AddWithValue("@BezierCusp", val);
//Only last value which i get in "val" after loop completes get Inserted into Database , but i want all the values to be inserted into database , how i can do this please suggest how should i rectify the problem...//
sqlInsertCmd.Connection = con;
SqlDataAdapter sqlDataAdapter3 = new SqlDataAdapter();
sqlDataAdapter3.InsertCommand = sqlInsertCmd;
con.Open();
sqlInsertCmd.ExecuteNonQuery();
con.Close();
Thanks alot sir, waiting for your response
with regards
Genius
|
|
|
|
|
I think that you have missed the point I was trying to make.
So I'll try again.
First pseudo-code
Setup all parameter(s) *** Note NOT AddWithValue here, just Add. This MUST only be done once, so outside loop ***
start loop
{
set value of parameter to next value from array *** NOTE this has to be done for each value, so inside loop ***
execute command to add/insert record
}
now with code from your original post
<big>sqlInsertCmd.Connection = con;</big> <=== Moved out of loop, only need to do it once, not for each iteration
<big>SqlParameter ciParam = sqlInsertCmd.Parameters.Add("@cuspIndex", SqlDbType.Int);</big>
<big>SqlParameter bcParam = sqlInsertCmd.Parameters.Add("@BezierCusp", SqlDbType.Int);</big>
for (i = 0; i <= 100; i = i + 1)
{
<big>ciParam.Value = Convert.ToInt16(stroke.BezierCusps.GetValue(i));</big>
<big>bcParam.Value = stroke.GetPoint(i).X;</big> <== Set the value of the parameter to the next value from the array
con.Open();
sqlInsertCmd.ExecuteNonQuery(); <== this stores value to database
con.Close();
}
I have highlighted code I have changed, or moved. I have had to make some assumptions about data types and how your data works, but I hope you get the idea.
Good Luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks alot , it really helped me
I really appreciate your Involvement in this forum
keep in touch
with regards
Genius
|
|
|
|
|
Thanks! My pleasure.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Is there a built in method of printing leading zeros with the likes of System.String.Fromat ?
A workaround isn't difficult but it messes up time critical functions.
Thanks.
|
|
|
|
|
Yes, there is. Use a zero specifier, as in string.Format("0000", 2) will print 0002.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
string.Format("{0:X5}", 16)
Will produce 000A0 .
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Oh, I messed that up, I did what I always do, I googled it ( I can't remember the format specifiers at all, I use them so rarely ). I event forgot the {0: } bit.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Ed.Poore wrote: Will produce 000A0
only if your fan broke down; 00010 is what I would expect.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
*phew* so, two out of three of us got it wrong. I don't feel so bad now, although mine was still the worst.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Luc Pattyn wrote: only if your fan broke down
Funny you should say that...
Speaking of fans, could do with a few more around the place to keep the house nice and cool...
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
seeing it has been rather hot here today, either you or your CPU could be running hot as well in the UK...
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Tell me about it, spent yesterday (now it's the morning) out in Brentwood doing some coaching. Skeet vest was black so not the best of colours...
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Thanks Ed, works fine.
I still can't find it in the documentation though
|
|
|
|
|
http://msdn.microsoft.com/en-us/library/txafckwd.aspx[^]
Look under the "Format String Component" heading and there's links to how to specify numeric, date and enumeration format codes. Did you really try to look? Quick Google and away it went (albeit I knew where I was going...)
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
I usually use Yahoo, need to try Google more often.
|
|
|
|
|
You're the one who still uses Yahoo ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Yeah, the structure of the documentation on formatting strings isn't very transparant,
I often need to search around a lot. Here[^] is what you want.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I tend to use number.ToString("X8") quite a lot.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hello Everyone,
I'm in the process of making a simple Bézier Curve editor for a time-lapse photography project, and was wondering how to correctly implement different "update cycles" for the control. By "update cycles" I'm referring to when the user clicks something draggable and moves it about, causing the control to enter a cycle where it updates and redraws itself.
Currently, I've tried using a combination of the MouseDown, MouseUp, MouseClick and MouseMove events, but it's a ghastly sight to behold, and seems to reek of bad programming practice. In order to complete a single task, you have to jump between the four different events.
So is there a proper and cleaner way to accomplish this? I'm not very experienced with custom controls, so any help would be greatly appreciated.
Regards,
Brandon Walton
|
|
|
|
|
Hi,
this works for me quite often in such situations:
1. use whatever mouse and keyboard events you need to update the status, but don't redraw (at most set a flag "needs repaint".
2. have a timer (Windows.System.Forms.Timer) periodically (say 4Hz) check the flag and call Invalidate().
This decouples user manipulations and repaints, solving the problem of how often to repaint.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Awesome, so when a MouseDown event is raised it'll keep redrawing until the follow-up MouseUp event, ridding the program of the MouseMove and MouseClick events. Blah, I should have thought of that . Thanks for the help!
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi, i am wondering to know how can i establish an internet connection via coding in C#.NET ?
-no matter it uses APIs or .Net Classes!
-no matter it executes on the background (without the end-user's permission) or executes by asking from the end-user!
=======
i tried to use APIs in the MSDN Library :
[DllImport("Wininet.dll", EntryPoint = "InternetGoOnline")]
with different Entry Points that the MSDN provided there but any of them worked in the final!
i am using VS 2008 in vista Ultimate and examine the code above in the Xp Too
|
|
|
|
|