胡神

导航

ExecuteNonQuery 简单sql语句

        /// <summary>
        /// 执行sql语句 ExecuteNonQuery
        /// </summary>
        /// <returns></returns>
        public static int sql()
        {
            string conString = "data source=.;Database=Codematic;user id=sa;password=123";
            SqlConnection myConnection = new SqlConnection(conString);
            string strSql = "update P_Product set Name='电脑 1' where id=52";

            myConnection.Open();
           // SqlCommand myCommand = new SqlCommand(strSql, myConnection);
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = strSql;
          
            int row = myCommand.ExecuteNonQuery();
            myConnection.Close();
            return row;
        }

posted on 2011-04-19 22:15  胡神  阅读(279)  评论(0)    收藏  举报