Click here to Skip to main content
15,886,519 members
Home / Discussions / C#
   

C#

 
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 
I added a line for clearing sql table before saving new data and then add new data. There are two problems:
C#
private void btnSave_Click(object sender, EventArgs e)
      {
          update.PerformClick();
          SqlCeConnection connection = new SqlCeConnection();
          connection.ConnectionString = @"Data Source=C:\Users\Dell\Desktop\DataGridView\PMinfo.sdf";
          SqlCeCommand myCommand = new SqlCeCommand();
          myCommand.Connection = connection;

          connection.Open();
          //Clearing data table
          myCommand.CommandText = "DELETE FROM PMinfo";
          connection.Close();

          myCommand.CommandText = @"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)";
          connection.Open();
          for (int i = 0; i < dataGridView1.Rows.Count; i++)
          {
              myCommand.Parameters.AddWithValue("@Number", dataGridView1.Rows[i].Cells[0].Value);
              myCommand.Parameters.AddWithValue("@CostCenter", dataGridView1.Rows[i].Cells[1].Value);
              myCommand.Parameters.AddWithValue("@pType", dataGridView1.Rows[i].Cells[2].Value);
              myCommand.Parameters.AddWithValue("@ServiceType", dataGridView1.Rows[i].Cells[3].Value);
              myCommand.Parameters.AddWithValue("@Receiver", dataGridView1.Rows[i].Cells[4].Value);
              myCommand.Parameters.AddWithValue("@WorkCenter", dataGridView1.Rows[i].Cells[5].Value);
              myCommand.Parameters.AddWithValue("@Start", dataGridView1.Rows[i].Cells[6].Value);
              myCommand.Parameters.AddWithValue("@End", dataGridView1.Rows[i].Cells[7].Value);
              myCommand.Parameters.AddWithValue("@Remaining", dataGridView1.Rows[i].Cells[8].Value);
              myCommand.Parameters.AddWithValue("@Status", dataGridView1.Rows[i].Cells[9].Value);
              myCommand.Parameters.AddWithValue("@ReceiveDate", dataGridView1.Rows[i].Cells[10].Value);


              myCommand.ExecuteNonQuery();
          }
          connection.Close();
      }

1- Clearing table doesn't work.
2- When I can more than 1 rowsin DataGridView, compliler gives following error:
C#
System.ArgumentException: 'The SqlCeParameter with this name is already contained by this SqlCeParameterCollection.'

I reviewed the loop but I couldn't find out the reason.
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 
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 

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.