Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay so what you are looking to do is insert to a database and not read from it so you therefore have to simply execute an sql query on the database and not read any data selected from it. For this you need to use the ExecuteNonQuery statement rather than the sqlDataReader. The result would look something like this</p> <pre><code>public static bool saveToDb(string name1, string nam2, DateTime dat) { bool ok = false; string sqlQuery = "INSERT INTO NumbersTable VALUES (@name1, @nam2, @dat)"; //This is the sql query we will use and by placing the @ symbol in front of words //Will establish them as variables and placeholders for information in an sql command //Next we create the sql command SqlCommand cmd = new SqlCommand(sqlQuery, con); //Here we will insert the correct values into the placeholders via the commands //parameters cmd.Parameters.AddWithValue("name1", name1); //This tells it to replace "@name1" with the value of name1 cmd.Parameters.AddWithValue("nam2", nam2); cmd.Parameters.AddWithValue("dat", dat); //Finally we open the connection con.Open(); //Lastly we tell the sql command to execute on the database, in this case inserting //the values int i = cmd.ExecuteNonQuery(); //Here we have the results of the execution stored in an integer, this is because //ExecuteNonQuery returns the number of rows it has effected, in the case of this //Insert statement it would effect one row by creating it, therefore i is 1 //This is useful for determining if your sql statement was successfully executed //As if it returns 0, nothing has happened and something has gone wrong con.Close(); } </code></pre> <p>I hope this has helped, if you need anything else feel free to ask.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload