Click here to Skip to main content
15,861,125 members
Home / Discussions / C#
   

C#

 
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.

Questioninteresting issue with SortedSet and ElementAt Pin
BillWoodruff22-Nov-20 18:59
professionalBillWoodruff22-Nov-20 18:59 
AnswerRe: interesting issue with SortedSet and ElementAt Pin
Sandeep Mewara22-Nov-20 20:06
mveSandeep Mewara22-Nov-20 20:06 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
BillWoodruff22-Nov-20 22:19
professionalBillWoodruff22-Nov-20 22:19 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
Sandeep Mewara22-Nov-20 22:38
mveSandeep Mewara22-Nov-20 22:38 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
BillWoodruff22-Nov-20 22:46
professionalBillWoodruff22-Nov-20 22:46 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
Sandeep Mewara22-Nov-20 22:51
mveSandeep Mewara22-Nov-20 22:51 
AnswerRe: interesting issue with SortedSet and ElementAt Pin
Richard Deeming22-Nov-20 22:15
mveRichard Deeming22-Nov-20 22:15 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
BillWoodruff22-Nov-20 22:40
professionalBillWoodruff22-Nov-20 22:40 
GeneralRe: interesting issue with SortedSet and ElementAt Pin
Richard Deeming22-Nov-20 22:58
mveRichard Deeming22-Nov-20 22:58 
Questionneed some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
albasheer210019-Nov-20 18:09
albasheer210019-Nov-20 18:09 
Rant[REPOST] need some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
Richard Deeming19-Nov-20 21:45
mveRichard Deeming19-Nov-20 21:45 
AnswerRe: need some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
Gerry Schmitz20-Nov-20 6:04
mveGerry Schmitz20-Nov-20 6:04 
QuestionHelp with Docker Pin
pkfox18-Nov-20 20:30
professionalpkfox18-Nov-20 20:30 
AnswerRe: Help with Docker Pin
Gerry Schmitz19-Nov-20 4:26
mveGerry Schmitz19-Nov-20 4:26 
GeneralRe: Help with Docker Pin
pkfox19-Nov-20 4:28
professionalpkfox19-Nov-20 4:28 
GeneralRe: Help with Docker Pin
Pete O'Hanlon19-Nov-20 4:39
subeditorPete O'Hanlon19-Nov-20 4:39 
GeneralRe: Help with Docker Pin
pkfox19-Nov-20 6:49
professionalpkfox19-Nov-20 6:49 

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.