OleDbCommand saveCmd = new OleDbCommand("INSERT INTO rapor (Proje_Adi, Proje_Tanimi, Proje_Sorumlusu, Kim_Verdi, Toplam_Sure, Sure_AsildiMi, Asilma_Sebepleri, Notlar, Baslangic_Tarihi, Bitis_Tarihi) VALUES ('" + adbox.Text + "','" + tanimbox.Text + "','" + comboBox1.Text + "','" + kimbox.Text + "','" + surebox.Text + "','" + checkBox1.Text + "','" + sebepbox.Text + "','" + notbox.Text + "','" + dateTimePicker1.Value + "','" + dateTimePicker2.Value + "')", raporCon);
                    int rowSay = saveCmd.ExecuteNonQuery();
                    if (rowSay == 1)
                        MessageBox.Show("...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        MessageBox.Show("...", "Hata!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                catch (Exception ex)
                    MessageBox.Show("...", MessageBoxButtons.OK, MessageBoxIcon.Error);

What is wrong with my codes, it doesn't load it in my access db. :/

Please give some more details about the errors you're getting. What isn't being saved? Is the connection open? Which messagebox is shown?

On the surface, your code looks fine.

"The variable ex is declared but never used" says as a warning. I don't get any errors, just can't understand why it doesn't load the entries in my access tables. When I click on the save button, I get the messagebox "Hata!"

Have you tried inputting your SQL manually through Access?

What is the value of rowSay after your ExecuteNonQuery() command?

Yeah, tried it through access just now, gives errors, tells about primary keys.. Could it be related to that? :S

The error is in Turkish, I don't know if I can translate it accurately and literraly, first alert box pops up saying add another row etc. smt like that, another one states an error about the primary key, didn't get why, I don't see errors neither in my tables nor my codes :/

OK I notice you haven't included it in your query. Is it set to "int" and have you made sure it Auto-Increments? These are settings you should be able to see in the properties window when you edit the table/column.

Yes to all.

It's my first c# project + I'm a female, this is the source of all errors. Ok, my boss told me to search how to insert the date with sql commands in access after checking my error but guess I still didn't get the hint. Could you? :S

Edited 6 Years Ago by Xinnie: n/a

It is probably a formatting problem between your local datetime and the database datetime.

Switch to using parameters. Here is an example of how to use them:

SqlCommand myCommand = new SqlCommand("INSERT INTO TestTable (theDate) VALUES(@dateTimeOne)", connection);
myCommand.Parameters.AddWithValue("dateTimeOne", DateTime.Now);
int rowsAff = myCommand.ExecuteNonQuery();

You should be able to utilise this method for your other variables.

This article has been dead for over six months. Start a new discussion instead.