0 Replies - 1487 Views - Last Post: 11 July 2019 - 02:34 PM

#1 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,165
  • Joined: 12-June 08

Basic SQL Command Setup

Posted 11 July 2019 - 02:34 PM

The basic steps of interacting with a database to UPDATE, INSERT, or DELETE.
            System.Data.DataSet ds;
            string sql = string.Empty;

            try
            {
                //1.  Open db connection
                using (SqlConnection con = new SqlConnection(""))// '-- AppSettings.Get("db")
                {
                    con.Open();

                    sql = "";// '-- 2.0  SQL statement.
                    using (SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, con))
                    {
                        // 2.1 parameters
                        cmd.Parameters.Add("", SqlDbType.VarChar).Value = "";

                        //2.2 execute your UPDATE, INSERT, DELETE
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }


Is This A Good Question/Topic? 1
  • +

Page 1 of 1