locked
C# inputting into SQL Database RRS feed

  • Question

  • I am working with C# and I can input data that I want into two columns into a SQL database with an application but the issues is the database needs to stay not null and I would like the rest of the fields to be automatically fill in.  How would I do that?

    This is what I got

    Id            CarSerialNumber             KindOfCar           CreateWho         EditDate               EditWho

    1              923432                                  Chev                      Null                        Null                        Null

    cmd = new SqlCommand("Insert Into dbo.repaircars (CarSerialNumber, KindOfCar ) VALUES (@CarSerialNumber,@ KindOfCar)", con);

    cmd.Parameters.Add("@CarSerialNumber", textBox1.Text);

    cmd.Parameters.Add("@KindOfCar", textBox2.Text);

    cmd.ExecuteNonQuery();

    What I need to happen for this table for this  SQL database is this without adding textbox3, textbox4. How would I do that?

    Id            CarSerialNumber             KindOfCar  CreateWho            EditDate                                EditWho

    1              923432                                      Chev          kbsmith           2019-04-06 13:29:34.392     bbc\kbsmith


    • Edited by Rag12345 Thursday, May 2, 2019 1:22 PM misspell title
    Thursday, May 2, 2019 1:21 PM

All replies

  • Hello!! My advice is that you add the other two parameters and put the following:

    System.DateTime.Now.Date.ToShortDateString();
    System.DateTime.Now.ToShortTimeString();

    P.S. You have to include the library "System.Data"

    Best regards

    Thursday, May 2, 2019 2:19 PM