Click here to Skip to main content
15,909,445 members
Home / Discussions / C#
   

C#

 
QuestionDifferences Pin
michaelbarb30-Nov-20 5:53
michaelbarb30-Nov-20 5:53 
AnswerRe: Differences Pin
OriginalGriff30-Nov-20 6:20
mveOriginalGriff30-Nov-20 6:20 
GeneralRe: Differences Pin
michaelbarb30-Nov-20 6:39
michaelbarb30-Nov-20 6:39 
QuestionIs my program idea possible? Pin
Dioxazine27-Nov-20 20:09
Dioxazine27-Nov-20 20:09 
AnswerRe: Is my program idea possible? Pin
OriginalGriff27-Nov-20 20:20
mveOriginalGriff27-Nov-20 20:20 
GeneralRe: Is my program idea possible? Pin
Dioxazine28-Nov-20 5:54
Dioxazine28-Nov-20 5:54 
GeneralRe: Is my program idea possible? Pin
OriginalGriff28-Nov-20 6:17
mveOriginalGriff28-Nov-20 6:17 
GeneralRe: Is my program idea possible? Pin
Dioxazine28-Nov-20 8:09
Dioxazine28-Nov-20 8:09 
GeneralRe: Is my program idea possible? Pin
OriginalGriff28-Nov-20 8:22
mveOriginalGriff28-Nov-20 8:22 
GeneralRe: Is my program idea possible? Pin
Liktor Janos11-Dec-20 7:42
Liktor Janos11-Dec-20 7:42 
GeneralRe: Is my program idea possible? Pin
Gerry Schmitz28-Nov-20 7:51
mveGerry Schmitz28-Nov-20 7:51 
QuestionError in SQL Light Compact 4 Pin
Alex Dunlop23-Nov-20 3:47
Alex Dunlop23-Nov-20 3:47 
AnswerRe: Error in SQL Light Compact 4 Pin
Victor Nijegorodov23-Nov-20 3:56
Victor Nijegorodov23-Nov-20 3:56 
GeneralRe: Error in SQL Light Compact 4 Pin
Alex Dunlop23-Nov-20 4:04
Alex Dunlop23-Nov-20 4:04 
GeneralRe: Error in SQL Light Compact 4 Pin
Richard Deeming23-Nov-20 4:18
mveRichard Deeming23-Nov-20 4:18 
GeneralRe: Error in SQL Light Compact 4 Pin
OriginalGriff23-Nov-20 4:29
mveOriginalGriff23-Nov-20 4:29 
GeneralRe: Error in SQL Light Compact 4 Pin
Alex Dunlop23-Nov-20 7:38
Alex Dunlop23-Nov-20 7:38 
GeneralRe: Error in SQL Light Compact 4 Pin
OriginalGriff23-Nov-20 7:53
mveOriginalGriff23-Nov-20 7:53 
GeneralRe: Error in SQL Light Compact 4 Pin
Alex Dunlop23-Nov-20 8:10
Alex Dunlop23-Nov-20 8:10 
GeneralRe: Error in SQL Light Compact 4 Pin
OriginalGriff23-Nov-20 8:19
mveOriginalGriff23-Nov-20 8:19 
GeneralRe: Error in SQL Light Compact 4 Pin
Alex Dunlop23-Nov-20 8:28
Alex Dunlop23-Nov-20 8:28 
GeneralRe: Error in SQL Light Compact 4 Pin
Richard Deeming23-Nov-20 17:43
mveRichard Deeming23-Nov-20 17:43 
GeneralRe: Error in SQL Light Compact 4 Pin
Alex Dunlop24-Nov-20 6:06
Alex Dunlop24-Nov-20 6:06 
GeneralRe: Error in SQL Light Compact 4 Pin
Dave Kreskowiak24-Nov-20 8:52
mveDave Kreskowiak24-Nov-20 8:52 
AnswerRe: Error in SQL Light Compact 4 Pin
Dave Kreskowiak23-Nov-20 5:58
mveDave Kreskowiak23-Nov-20 5:58 
What nobody mentioned is you are constantly adding new parameters to the SqlCommand.Parameters, on every pass of the loop.

You're not reusing parameters, you're creating new ones on every iteration of the loop. On the first iteration of the loop, your Parameters collection will have 11 parameters. On the second, 22 parameters. On the 3rd, 33 parameters...

Create the parameters OUTSIDE the loop, then just set the values inside.
C#
SqlCeConnection connection = new SqlCeConnection();
            connection.ConnectionString = @"Data Source=C:\Users\Dell\Desktop\DataGridView\PMinfo.sdf";

            SqlCeCommand myCommand = new SqlCeCommand(@"INSERT into [PMinfo] (Number, CostCenter, pType, ServiceType, Receiver, WorkCenter, Start, End, Remaining, Status, ReceiveDate) values(@Number, @CostCenter, @pType, @ServiceType, @Receiver, @WorkCenter, @Start, @End, @Remaining, @Status, @ReceiveDate)");

            myCommand.Connection = connection;

            //
            // You'll have to set the DB type of each parameter to what the database expects.
            //
            myCommand.Parameters.Add("@Number", SqlDbType.NVarChar);
            myCommand.Parameters.Add("@CostCenter", ...);
            myCommand.Parameters.Add("@pType", ...);
            myCommand.Parameters.Add("@ServiceType", ...);
            myCommand.Parameters.Add("@Receiver", ...);
            myCommand.Parameters.Add("@WorkCenter", ...);
            myCommand.Parameters.Add("@Start", ...);
            myCommand.Parameters.Add("@End", ...);
            myCommand.Parameters.Add("@Remaining", ...);
            myCommand.Parameters.Add("@Status", ...);
            myCommand.Parameters.Add("@ReceiveDate", ...);

            connection.Open();

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                myCommand.Parameters["@Name"] = dataGridView1.Rows[i].Cells[0].Value.ToString();
                myCommand.Parameters["@CostCenter"] = ...
                ...

                myCommand.ExecuteNonQuery();
            }

            connection.Close();

DO NOT STORE DATES AS STRINGS IN THE DATABASE! Store them as the appropriate DateTime type.

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.